diff --git a/examples/src/TcpExamples/TcpExample4DispatchServer.java b/examples/src/TcpExamples/TcpExample4DispatchServer.java index d889c89002b2663d85764ec45a88b4e9495c0388..b9d3d4f1b2adcb118314a90db9c3fe4e5a287a25 100644 --- a/examples/src/TcpExamples/TcpExample4DispatchServer.java +++ b/examples/src/TcpExamples/TcpExample4DispatchServer.java @@ -42,16 +42,21 @@ public class TcpExample4DispatchServer System.out.println(TcpExample4DispatchServer.class.getName() + " ready to accept socket connections..."); while (true) // infinite loop { - clientConnection = serverSocket.accept(); // block until connected + clientConnection = 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 + System.out.println("============================================================="); - System.out.println(TcpExample4DispatchServer.class.getName() + ".handlerThread invocation for connection #" + connectionCount + "..."); - handlerThread = new TcpExample4HandlerThread(clientConnection); - handlerThread.start(); // invokes the run() method in that object - System.out.println(TcpExample4DispatchServer.class.getName() + ".handlerThread is launched, awaiting another connection..."); + System.out.println(TcpExample4DispatchServer.class.getName() + ".handlerThread created for connection #" + connectionCount + "..."); + handlerThread = new TcpExample4HandlerThread(clientConnection); // hand off the aready-created, connected socket to constructor + 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..."); } - } catch (IOException e) { + } + catch (IOException e) { System.out.println("Problem with " + TcpExample4DispatchServer.class.getName() + " networking:"); // describe what is happening System.out.println("Error: " + e); // Provide more helpful information to user if exception occurs due to running twice at one time