// 'ClientSession' code file import java.awt.*; import java.net.*; import java.io.*; class ClientSession extends Thread { Socket socket = null; DataInputStream input = null; DataOutputStream output = null; ClientSession(String host,int port){ try { socket = new Socket(host,port,true); input = new DataInputStream(socket.getInputStream()); output = new DataOutputStream(socket.getOutputStream()); } catch (UnknownHostException e){} catch (IOException e){} } void kill(){ stop(); try {socket.close();} catch (IOException e){} } public void run(){ // reading blocks byte buf[]; int size; if (input==null) return; // failed to connect while (true) { try { size = input.readInt(); buf = new byte[size]; input.read(buf); // fill message TextBuffer respond(buf); } catch (IOException e){kill();} } } void send(byte buf[]){ // this is how you send messages to the server int size = buf.length; try { output.writeInt(size); output.write(buf,0,size); } catch (IOException e){kill();} } void respond(byte buf[]){ // this is where you respond to server messages } }