Skip to content
Snippets Groups Projects
Commit 900e79c7 authored by rojas's avatar rojas
Browse files

Merge origin/master

Conflicts:
	assignments/nbproject/build-impl.xml
	assignments/nbproject/project.properties
	examples/nbproject/build-impl.xml
parents 1b018ffa 671f8450
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
......@@ -37,10 +37,10 @@ public class TcpExample4Client
public static void main(String[] args) {
try {
System.out.println(TcpExample4Client.class.getName() + " start, loop " + MAX_LOOP_COUNT + " times");
System.out.println("==================================================");
System.out.println("=======================================================");
for (int loopCount = 1; loopCount <= MAX_LOOP_COUNT; loopCount++) // loop then exit
{
System.out.println(TcpExample4Client.class.getName() + " creating socket #" + loopCount + "...");
System.out.println(TcpExample4Client.class.getName() + " creating new socket #" + loopCount + "...");
// We request an IP to connect to ("localhost") and
// port number at that IP (2317). This establishes
......@@ -67,7 +67,7 @@ public class TcpExample4Client
System.out.println(TcpExample4Client.class.getName() + ": message received from server='" + serverMessage + "'");
System.out.println(TcpExample4Client.class.getName() + ": time msec required for read=" + timeLength);
System.out.println("==================================================");
System.out.println("=======================================================");
// To push this further, launch multiple copies of TcpExample4Client simultaneously
}
System.out.println(TcpExample4Client.class.getName() + " complete");
......
......@@ -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
......
......@@ -31,9 +31,9 @@ public class TcpExample4HandlerThread extends Thread
/** The socket connection to a client */
Socket socket;
/** The thread constructor creates the socket from
* a ServerSocket, and passes one to the thread
* responsible for handling the connection.
/**
* The thread constructor creates the socket from a ServerSocket, waiting for the client to connect,
* and passes that socket when constructing the thread responsible for handling the connection.
*
* @param socket The socket connection handled by this thread
*/
......@@ -41,6 +41,15 @@ public class TcpExample4HandlerThread extends Thread
{
this.socket = socket;
}
/**
* Program invocation and execution starts here - but is illegal and unwanted, so warn the unsuspecting user!
* @param args command-line arguments
*/
public static void main(String[] args)
{
System.out.println ("*** TcpExample4HandlerThread is not a standalone executable progam.");
System.out.println ("*** Please run TcpExample4DispatchServer instead... now exiting.");
}
/** Handles one connection. We add an artificial slowness
* to handling the connection with a sleep(). This means
......
examples/src/TcpExamples/TcpExample4SequenceDiagram.png

130 KiB | W: | H:

examples/src/TcpExamples/TcpExample4SequenceDiagram.png

17.6 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
Invocation instructions:
1. run/debug TcpExample4ThreadTcpExample4DispatchServerServer.java
1. run/debug TcpExample4ThreadTcpExample4DispatchServer.java
2. don't run TcpExample4HandlerThread (since it is automatically launched as needed)
3. run/debug TcpExample4Client.java
......@@ -7,63 +7,74 @@ Two program response logs, server and client:
===================================================
===================================================
run:
ant -f C:\\x-nps-gitlab\\NetworkedGraphicsMV3500\\examples -Dnb.internal.action.name=run.single -Djavac.includes=TcpExamples/TcpExample4DispatchServer.java -Drun.class=TcpExamples.TcpExample4DispatchServer run-single
TcpExample4DispatchServer.java
ant -f C:\\x3d-nps-gitlab\\NetworkedGraphicsMV3500\\examples -Dnb.internal.action.name=run.single -Djavac.includes=TcpExamples/TcpExample4DispatchServer.java -Drun.class=TcpExamples.TcpExample4DispatchServer run-single
init:
Deleting: C:\x3d-nps-gitlab\NetworkedGraphicsMV3500\examples\build\built-jar.properties
deps-jar:
Updating property file: C:\x3d-nps-gitlab\NetworkedGraphicsMV3500\examples\build\built-jar.properties
Compiling 1 source file to C:\x3d-nps-gitlab\NetworkedGraphicsMV3500\examples\build\classes
compile-single:
run-single:
TcpExamples.TcpExample4DispatchServer ready to accept socket connections...
=============================================================
TcpExamples.TcpExample4DispatchServer.handlerThread invocation for connection #1...
TcpExamples.TcpExample4DispatchServer.handlerThread is launched, awaiting another connection...
TcpExamples.TcpExample4DispatchServer.handlerThread created for connection #1...
TcpExamples.TcpExample4DispatchServer.handlerThread is now dispatched and running, using most recent connection...
TcpExamples.TcpExample4HandlerThread starting to handle a thread...
TcpExamples.TcpExample4HandlerThread pausing for TIMEOUT=2000ms to emulate computation and avoid server-side overload
TcpExamples.TcpExample4HandlerThread finished handling a thread, now exit.
=============================================================
TcpExamples.TcpExample4DispatchServer.handlerThread invocation for connection #2...
TcpExamples.TcpExample4DispatchServer.handlerThread is launched, awaiting another connection...
TcpExamples.TcpExample4DispatchServer.handlerThread created for connection #2...
TcpExamples.TcpExample4DispatchServer.handlerThread is now dispatched and running, using most recent connection...
TcpExamples.TcpExample4HandlerThread starting to handle a thread...
TcpExamples.TcpExample4HandlerThread pausing for TIMEOUT=2000ms to emulate computation and avoid server-side overload
TcpExamples.TcpExample4HandlerThread finished handling a thread, now exit.
=============================================================
TcpExamples.TcpExample4DispatchServer.handlerThread invocation for connection #3...
TcpExamples.TcpExample4DispatchServer.handlerThread is launched, awaiting another connection...
TcpExamples.TcpExample4DispatchServer.handlerThread created for connection #3...
TcpExamples.TcpExample4DispatchServer.handlerThread is now dispatched and running, using most recent connection...
TcpExamples.TcpExample4HandlerThread starting to handle a thread...
TcpExamples.TcpExample4HandlerThread pausing for TIMEOUT=2000ms to emulate computation and avoid server-side overload
TcpExamples.TcpExample4HandlerThread finished handling a thread, now exit.
=============================================================
TcpExamples.TcpExample4DispatchServer.handlerThread invocation for connection #4...
TcpExamples.TcpExample4DispatchServer.handlerThread is launched, awaiting another connection...
TcpExamples.TcpExample4DispatchServer.handlerThread created for connection #4...
TcpExamples.TcpExample4DispatchServer.handlerThread is now dispatched and running, using most recent connection...
TcpExamples.TcpExample4HandlerThread starting to handle a thread...
TcpExamples.TcpExample4HandlerThread pausing for TIMEOUT=2000ms to emulate computation and avoid server-side overload
TcpExamples.TcpExample4HandlerThread finished handling a thread, now exit.
BUILD STOPPED (total time: 25 seconds)
===================================================
===================================================
run:
ant -f C:\\x-nps-gitlab\\NetworkedGraphicsMV3500\\examples -Dnb.internal.action.name=run.single -Djavac.includes=TcpExamples/TcpExample4Client.java -Drun.class=TcpExamples.TcpExample4Client run-single
TcpExample4Client.java
run:
ant -f C:\\x3d-nps-gitlab\\NetworkedGraphicsMV3500\\examples -Dnb.internal.action.name=run.single -Djavac.includes=TcpExamples/TcpExample4Client.java -Drun.class=TcpExamples.TcpExample4Client run-single
init:
Deleting: C:\x3d-nps-gitlab\NetworkedGraphicsMV3500\examples\build\built-jar.properties
deps-jar:
Updating property file: C:\x3d-nps-gitlab\NetworkedGraphicsMV3500\examples\build\built-jar.properties
Compiling 1 source file to C:\x3d-nps-gitlab\NetworkedGraphicsMV3500\examples\build\classes
compile-single:
run-single:
TcpExamples.TcpExample4Client start, loop 4 times
==================================================
TcpExamples.TcpExample4Client creating socket #1...
=======================================================
TcpExamples.TcpExample4Client creating new socket #1...
TcpExamples.TcpExample4Client: message received from server='This message was written by the server TcpExamples.TcpExample4HandlerThread'
TcpExamples.TcpExample4Client: time msec required for read=2024
==================================================
TcpExamples.TcpExample4Client creating socket #2...
TcpExamples.TcpExample4Client: time msec required for read=2033
=======================================================
TcpExamples.TcpExample4Client creating new socket #2...
TcpExamples.TcpExample4Client: message received from server='This message was written by the server TcpExamples.TcpExample4HandlerThread'
TcpExamples.TcpExample4Client: time msec required for read=2008
==================================================
TcpExamples.TcpExample4Client creating socket #3...
TcpExamples.TcpExample4Client: time msec required for read=2006
=======================================================
TcpExamples.TcpExample4Client creating new socket #3...
TcpExamples.TcpExample4Client: message received from server='This message was written by the server TcpExamples.TcpExample4HandlerThread'
TcpExamples.TcpExample4Client: time msec required for read=2007
==================================================
TcpExamples.TcpExample4Client creating socket #4...
TcpExamples.TcpExample4Client: time msec required for read=2014
=======================================================
TcpExamples.TcpExample4Client creating new socket #4...
TcpExamples.TcpExample4Client: message received from server='This message was written by the server TcpExamples.TcpExample4HandlerThread'
TcpExamples.TcpExample4Client: time msec required for read=2011
==================================================
TcpExamples.TcpExample4Client: time msec required for read=2016
=======================================================
TcpExamples.TcpExample4Client complete
BUILD SUCCESSFUL (total time: 8 seconds)
BUILD SUCCESSFUL (total time: 9 seconds)
===================================================
===================================================
\ No newline at end of file
No preview for this file type
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