import java.net.*; import java.io.*; public class TCPEchoServer{ private static final int BUFSIZE = 32; public static void main(String[] args) throws IOException{ ServerSocket servSock = new ServerSocket(24000); byte [] receiveBuf = new byte[BUFSIZE]; while(true){ System.out.println("Waiting for a Client"); Socket clntSock = servSock.accept(); SocketAddress clientAddress = clntSock.getRemoteSocketAddress(); System.out.println("Handling Client at " + clientAddress); InputStream in = clntSock.getInputStream(); OutputStream out = clntSock.getOutputStream(); int recvMsgSize; while( (recvMsgSize = in.read(receiveBuf)) != -1){ /* System.out.println("Received " + recvMsgSize + " bytes"); */ out.write(receiveBuf,0, recvMsgSize); } clntSock.close(); } /* NOT REACHED*/ } }