package org.kne.cloud.network.klalb;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.net.SocketException;
import java.nio.Buffer;

public class StreamKLALBPacketLink implements KLALBPacketLink {

	@Override
	public String toString() {
		return "StreamKLALBPacketLink [connectSocket=" + connectSocket + "]";
	}

	private Socket connectSocket;
	private KLALBInputStream in;
	private KLALBOutputStream out;
	public StreamKLALBPacketLink(Socket connectSocket) throws IOException {
		this.connectSocket=connectSocket;
		connectSocket.setTcpNoDelay(true);
		out=new KLALBOutputStream(connectSocket.getOutputStream());
		out.flush();
		in=new KLALBInputStream( connectSocket.getInputStream());
		//connectSocket.setSendBufferSize(1024*1024*1024);
	}
	
	@Override
	public void writePacket(KLALBPacket kp) throws IOException {
		out.writePacket(kp);
	}

	@Override
	public KLALBPacket readPacket() throws IOException {
		return in.readPacket();
	}

	@Override
	public void close() throws IOException {
		connectSocket.close();
	}

	@Override
	public boolean isClosed() {
		return connectSocket.isClosed();
	}

	@Override
	public void setSoTimeout(int val) throws SocketException {
		connectSocket.setSoTimeout(val);
	}

	@Override
	public int getSoTimeout() throws SocketException {
		return	connectSocket.getSoTimeout();
	}

}
