Skip to content
Snippets Groups Projects
Commit 502e3d32 authored by Brutzman, Don's avatar Brutzman, Don
Browse files

improved comments

parent 3159460c
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment