diff --git a/examples/src/TcpExamples/TcpExample4DispatchServer.java b/examples/src/TcpExamples/TcpExample4DispatchServer.java index b9d3d4f1b2adcb118314a90db9c3fe4e5a287a25..c03fcf080c9a36049013aebe7a5608ed48f1d8c5 100644 --- a/examples/src/TcpExamples/TcpExample4DispatchServer.java +++ b/examples/src/TcpExamples/TcpExample4DispatchServer.java @@ -33,27 +33,33 @@ public class TcpExample4DispatchServer public static void main(String[] args) { try { - ServerSocket serverSocket = new ServerSocket(2317); + ServerSocket serverSocket = new ServerSocket(2317); + Socket clientConnectionSocket; TcpExample4HandlerThread handlerThread; - Socket clientConnection; int connectionCount = 0; // state variable System.out.println(TcpExample4DispatchServer.class.getName() + " ready to accept socket connections..."); while (true) // infinite loop { - clientConnection = serverSocket.accept(); // block! until connected + clientConnectionSocket = serverSocket.accept(); // block! until connected connectionCount++; // unblocked, got another connection - // TODO provide initial message *to the client* that we are handing off to a dispatch thread... because that is polite behavior. - // plenty of code in Example3, we will let TcpExample4HandlerThread introduce itself + // TODO option for the student, provide initial message *to the client* + // that we are handing off to a dispatch thread... because that is polite behavior. + // Plenty of code in Example3, we instead let our proxy thread + // TcpExample4HandlerThread introduce itself to the client. System.out.println("============================================================="); System.out.println(TcpExample4DispatchServer.class.getName() + ".handlerThread created for connection #" + connectionCount + "..."); - handlerThread = new TcpExample4HandlerThread(clientConnection); // hand off the aready-created, connected socket to constructor + + // hand off this aready-created and connected socket to constructor + handlerThread = new TcpExample4HandlerThread(clientConnectionSocket); handlerThread.start();// invokes the run() method in that object System.out.println(TcpExample4DispatchServer.class.getName() + ".handlerThread is now dispatched and running, using most recent connection..."); + + // while(true) continue looping, serverSocket is still waiting for another customer client } } catch (IOException e) { @@ -64,6 +70,6 @@ public class TcpExample4DispatchServer System.out.println("*** Be sure to stop any other running instances of programs using this port!"); } } - System.out.println("============================================================="); + System.out.println("============================================================="); // execution complete } }