Skip to content
Snippets Groups Projects
Commit 53dfef95 authored by ethanjwilliams's avatar ethanjwilliams
Browse files

Merge origin/master

parents e8c1a1cc 4f5cbf72
No related branches found
No related tags found
No related merge requests found
...@@ -33,27 +33,33 @@ public class TcpExample4DispatchServer ...@@ -33,27 +33,33 @@ public class TcpExample4DispatchServer
public static void main(String[] args) public static void main(String[] args)
{ {
try { try {
ServerSocket serverSocket = new ServerSocket(2317); ServerSocket serverSocket = new ServerSocket(2317);
Socket clientConnectionSocket;
TcpExample4HandlerThread handlerThread; TcpExample4HandlerThread handlerThread;
Socket clientConnection;
int connectionCount = 0; // state variable int connectionCount = 0; // state variable
System.out.println(TcpExample4DispatchServer.class.getName() + " ready to accept socket connections..."); System.out.println(TcpExample4DispatchServer.class.getName() + " ready to accept socket connections...");
while (true) // infinite loop while (true) // infinite loop
{ {
clientConnection = serverSocket.accept(); // block! until connected clientConnectionSocket = serverSocket.accept(); // block! until connected
connectionCount++; // unblocked, got another connection 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. // TODO option for the student, provide initial message *to the client*
// plenty of code in Example3, we will let TcpExample4HandlerThread introduce itself // 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("=============================================================");
System.out.println(TcpExample4DispatchServer.class.getName() + ".handlerThread created for connection #" + connectionCount + "..."); 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 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..."); 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) { catch (IOException e) {
...@@ -64,6 +70,6 @@ public class TcpExample4DispatchServer ...@@ -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("*** Be sure to stop any other running instances of programs using this port!");
} }
} }
System.out.println("============================================================="); System.out.println("============================================================="); // execution complete
} }
} }
examples/src/TcpExamples/TcpExample4SequenceDiagram.png

17.6 KiB | W: | H:

examples/src/TcpExamples/TcpExample4SequenceDiagram.png

21.2 KiB | W: | H:

examples/src/TcpExamples/TcpExample4SequenceDiagram.png
examples/src/TcpExamples/TcpExample4SequenceDiagram.png
examples/src/TcpExamples/TcpExample4SequenceDiagram.png
examples/src/TcpExamples/TcpExample4SequenceDiagram.png
  • 2-up
  • Swipe
  • Onion skin
No preview for this file type
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