From 502e3d328598edd69da4d8a8022a9bab4e0206a0 Mon Sep 17 00:00:00 2001 From: brutzman <brutzman@nps.edu> Date: Tue, 30 Jul 2024 12:51:28 -0700 Subject: [PATCH] improved comments --- .../TcpExample4DispatchServer.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/examples/src/TcpExamples/TcpExample4DispatchServer.java b/examples/src/TcpExamples/TcpExample4DispatchServer.java index b9d3d4f1b2..c03fcf080c 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 } } -- GitLab