import java.net.*; import java.io.*; //adapted from Sun's KnockKnockServer example from the Java Tutorial public class TransServer { public static void main(String[] args) throws IOException { ServerSocket serverSocket = null; try { serverSocket = new ServerSocket(4444); } catch (IOException e) { System.err.println("Could not listen on port: 4444."); System.exit(1); } Socket clientSocket = null; try { System.out.println("Accepting client..."); clientSocket = serverSocket.accept(); System.out.println("Client accepted"); } catch (IOException e) { System.err.println("Accept failed."); System.exit(1); } PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); BufferedReader in = new BufferedReader( new InputStreamReader( clientSocket.getInputStream())); String inputLine, outputLine; TransProtocol tp = new TransProtocol(); outputLine = tp.processInput(null); out.println(outputLine); while ((inputLine = in.readLine()) != null) { outputLine = tp.processInput(inputLine); out.println(outputLine); if (outputLine.equals("Bye")) break; } System.out.println("Exited loop!.... Bye Bye!"); out.close(); in.close(); clientSocket.close(); serverSocket.close(); } }