diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework1/FisherTCPExample1Telnet.java b/assignments/src/MV3500Cohort2021JulySeptember/homework1/FisherTCPExample1Telnet.java index d925c7fdc0b4cb83e4cd3eec4a662be1c4b49a09..91f18ffa79d3cd8ba9126bd8e399d3b57b10d304 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework1/FisherTCPExample1Telnet.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework1/FisherTCPExample1Telnet.java @@ -46,7 +46,7 @@ public class FisherTCPExample1Telnet { // across what is in fact a slow connection ps.flush(); } - System.out.println("TcpExample1 completed successfully."); + System.out.println("FisherTCPExample1 completed successfully."); } catch(IOException e) { diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/AllenTcpExample3Client.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/AllenTcpExample3Client.java new file mode 100644 index 0000000000000000000000000000000000000000..ef9b10791b649039f00c9d6260a0919c9fa49d9a --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/AllenTcpExample3Client.java @@ -0,0 +1,93 @@ +package MV3500Cohort2021JulySeptember.homework2; + +import java.io.*; +import java.net.*; + +/** + * Before, we always used telnet (netcat) to connect to the server. Here we are + * now writing our own program to do the connection. + * + * As you will see, when we run this after we start the server we will see the + * same string telnet printed, sent by the server. The output at the server will + * show different socket pairs for each time the loop iterates. + * + * @author snapp + */ +public class AllenTcpExample3Client { + + /** IPv6 String constant for localhost address, similarly IPv4 127.0.0.1 + * @see <a href="https://en.wikipedia.org/wiki/localhost">https://en.wikipedia.org/wiki/localhost</a> + * @see <a href="https://en.wikipedia.org/wiki/IPv6_address">https://en.wikipedia.org/wiki/IPv6_address</a> + */ + public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; + + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ + public static void main(String[] args) throws InterruptedException { + + // Local variables/fields + Socket socket = null; + InputStream is; + Reader isr; + BufferedReader br; + String serverMessage; + int clientLoopCount = 0; + + try { + while (true) + { + clientLoopCount++; // increment at beginning of loop for reliability + System.out.println(AllenTcpExample3Client.class.getName() + " creating socket..."); + + // We request an IP to connect to ("localhost") and + // port number at that IP (2317). This establishes + // a connection to that IP in the form of a Socket + // object; the server uses a ServerSocket to wait for + // connections. + socket = new Socket(LOCALHOST, 2317); // locohost? + + // Now hook everything up (i.e. set up the streams), Java style: + is = socket.getInputStream(); + isr = new InputStreamReader(is); + br = new BufferedReader(isr); + + // Read a single line written by the server. We'd + // do things a bit differently if there were many lines to be read + // from the server instead of one only. + serverMessage = br.readLine(); + System.out.println("=================================================="); + System.out.println("Sorry, my dog ate my homework."); + System.out.println("The AllenServer responds with: " + serverMessage + "'"); + System.out.println("Yeah, it took him a few bytes! This this my " + clientLoopCount +" time trying to contact you."); + + // socket gets closed, either automatically/silently by this code (or possibly by the server) + + Thread.sleep(500l); // slow things down, for example 500l (long) = 500 msec + + } // end while(true) // infinite loops are dangerous, be sure to kill this process! + } + catch (IOException e) + { + System.err.println("Problem with " + AllenTcpExample3Client.class.getName() + " networking:"); // describe what is happening + System.err.println("Error: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + finally // occurs after any other activity when shutting down + { + try { + if (socket != null) + socket.close(); + } catch (IOException e) {} + + // program exit: tell somebody about that happening. Likely cause: server drops connection. + System.out.println(); + System.out.println(AllenTcpExample3Client.class.getName() + " exit"); + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/AllenTcpExample3Server.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/AllenTcpExample3Server.java new file mode 100644 index 0000000000000000000000000000000000000000..912102f5ec3dacfe25834c8acecace1dc93e8ea9 --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/AllenTcpExample3Server.java @@ -0,0 +1,102 @@ +package MV3500Cohort2021JulySeptember.homework2; + +import java.io.*; +import java.net.*; + +/** + * Very slightly more complex than example1, further modifying example2. The + * only thing this does differently is introduce a loop into the response, so + * you don't have to restart the program after one response. Also, it prints out + * the socket pair the server sees. Run the program via telnet several times and + * compare the socket pairs. + * + * telnet (nc) localhost 2317 + * + * If you're sophisticated you can contact the instructor's computer while + * running this program. + * + * telnet (nc) [ipNumberOfServerLaptop] 2317 + * + * and have the instructor display the socket pairs received. + * + * @snapp + */ +public class AllenTcpExample3Server { + + /** + * Program invocation, execution starts here + * If already compiled, can run using console in directory ../../build/classes/ by invoking \ + * java -classpath . TcpExamples.TcpExample3Server + * @param args command-line arguments + */ + public static void main(String[] args) { + try { + + // ServerSocket waits for a connection from a client. + // Notice that it is outside the loop; ServerSocket + // needs to be made only once. + System.out.println(AllenTcpExample3Server.class.getName() + " has started..."); // it helps debugging to put this on console first + + ServerSocket serverSocket = new ServerSocket(2317); + OutputStream os; + PrintStream ps; + InetAddress localAddress, remoteAddress; + int localPort, remotePort; + int serverLoopCount = 0; + + // Server is up and waiting (i.e. "blocked" or paused) + // Loop, infinitely, waiting for client connections. + // Stop the program somewhere else. + while (true) { + + // block until connected to a client + try (Socket clientConnectionSocket = serverSocket.accept()) + { + serverLoopCount++; // increment at beginning of loop for reliability + + // Now hook everything up (i.e. set up the streams), Java style: + os = clientConnectionSocket.getOutputStream(); + ps = new PrintStream(os); + ps.println("This is response " + serverLoopCount + " produced by the server. Your dog ate your coding assignment?"); // this gets sent back to client! + + // Print some information locally about the Socket connection. + // This includes the port and IP numbers on both sides (the socket pair). + localAddress = clientConnectionSocket.getLocalAddress(); + remoteAddress = clientConnectionSocket.getInetAddress(); + localPort = clientConnectionSocket.getLocalPort(); + remotePort = clientConnectionSocket.getPort(); + + System.out.print ("Server loop " + serverLoopCount + ": "); + + // My socket pair connection looks like this, to localhost: + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 )) + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) + + // Why is the first IP/port the same, while the second set has different ports? + System.out.println(AllenTcpExample3Server.class.getName() + " socket pair showing host name, address, port:"); + System.out.println(" (( " + + localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( " + + remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))"); + + if ( localAddress.getHostName().equals( localAddress.getHostAddress()) || + remoteAddress.getHostName().equals(remoteAddress.getHostAddress())) + System.out.println(" note HostName matches address if host has no DNS name"); + + // Notice the use of flush() and try w/ resources. Without + // the try w/ resources the Socket object may stay open for + // a while after the client has stopped needing this + // connection. try w/ resources explicitly ends the connection. + ps.flush(); + // like it or not, you're outta here! + } + } + } catch (IOException e) { + System.err.println("Problem with " + AllenTcpExample3Server.class.getName() + " networking: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Fisher/FisherClient.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Fisher/FisherClient.java new file mode 100644 index 0000000000000000000000000000000000000000..00de0484e3b43b1a65a98be8f45d2ab5f96f8339 --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Fisher/FisherClient.java @@ -0,0 +1,93 @@ +package MV3500Cohort2021JulySeptember.homework2.Fisher; + +//import static MV3500Cohort2020JulySeptember.homework2.White.WhiteClient.LOCALHOST; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.PrintStream; +import java.net.Socket; + +/** + * Before, we always used telnet (netcat) to connect to server. Here we are + * now writing our own program to do the connection. + * + * As you will see, when we run this after we start the server we will see the + * same string telnet printed, sent by the server. The output at the server will + * show different socket pairs for each time the loop iterates. + * + * @author adfis + */ +public class FisherClient { + + // IPv6 String constant for localhost address, similarly IPv4 127.0.0.1 + public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; + // Sub with someone's IP + // Got it to work with McNeely in class + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ + public static void main(String[] args) { + + // Local variables/fields + Socket socket; + InputStream is; + InputStreamReader isr; + BufferedReader br; + OutputStream os; + PrintStream ps; + String serverMessage; + int clientLoopCount = 1; + + try { + System.out.println("FisherClient creating socket..."); + // Made a loop counter for client to stop after 10 pings with server + while (clientLoopCount <= 10) { + + // We request an IP to connect to ("localhost") and + // port number at that IP (2317). This establishes + // a connection to that IP in the form of a Socket + // object; the server uses a ServerSocket to wait for + // connections. + socket = new Socket(LOCALHOST, 2317); + + os = socket.getOutputStream(); + ps = new PrintStream(os); + + // Now hook everything up (i.e. set up the streams), Java style: + is = socket.getInputStream(); + isr = new InputStreamReader(is); + br = new BufferedReader(isr); + + // Read a single line written by the server. We'd + // do things a bit differently if there were many lines to be read + // from the server instead of one only. + serverMessage = br.readLine(); + System.out.println("=================================================="); + + System.out.println("The message the server sent was: '" + serverMessage + "'"); + System.out.println("FisherClient responds with: To get to the other side"); + System.out.println("Loop count: " + clientLoopCount); + clientLoopCount++; + // socket gets closed, either automatically/silently by this code (or possibly by the server) + + } // end while(true) + } catch (IOException e) { + System.err.println("Problem with FisherClient networking:"); // describe what is happening + System.err.println("Error: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } finally // occurs after any other activity when shutting down + { + // program exit: tell somebody about that happening. Likely cause: server drops connection. + System.out.println(); + System.out.println("FisherClient exit"); + } + } + +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Fisher/FisherServer.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Fisher/FisherServer.java new file mode 100644 index 0000000000000000000000000000000000000000..c6b16ee66f6232df0f0735a47b0f92d762a3a038 --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Fisher/FisherServer.java @@ -0,0 +1,116 @@ +package MV3500Cohort2021JulySeptember.homework2.Fisher; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.PrintStream; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; + +/** + * Very slightly more complex than example1, further modifying example2. The + * only thing this does differently is introduce a loop into the response, so + * you don't have to restart the program after one response. Also, it prints out + * the socket pair the server sees. Run the program via telnet several times and + * compare the socket pairs. + * + * telnet (nc) localhost 2317 + * + * If you're sophisticated you can contact the instructor's computer while + * running this program. + * + * telnet (nc) [ipNumberOfServerLaptop] 2317 + * + * and have the instructor display the socket pairs received. + * + * @author adfis + */ +public class FisherServer { + + /** + * @param args command-line arguments + */ + public static void main(String[] args) { + try { + + // ServerSocket waits for a connection from a client. + // Notice that it is outside the loop; ServerSocket + // needs to be made only once. + System.out.println("FisherServer has started..."); // it helps debugging to put this on console first + + ServerSocket serverSocket = new ServerSocket(2317); + OutputStream os; + PrintStream ps; + InetAddress localAddress, remoteAddress; + int localPort, remotePort; + + InputStream is; + InputStreamReader isr; + BufferedReader br; + int serverLoopCount = 1; + + + // Server is up and waiting (i.e. "blocked" or paused) + // Loop, infinitely, waiting for client connections. + // Stop the program somewhere else. + // Made a loop counter for server to stop after 10 pings with client + while (serverLoopCount <= 10) { + + // block until connected to the client + try ( Socket clientConnectionSocket = serverSocket.accept()) { + + // Now hook everything up (i.e. set up the streams), Java style: + os = clientConnectionSocket.getOutputStream(); + ps = new PrintStream(os); + ps.println("Why did the chicken cross the road?"); // this gets sent back to client! + + // Print some information locally about the Socket connection. + // This includes the port and IP numbers on both sides (the socket pair). + localAddress = clientConnectionSocket.getLocalAddress(); + remoteAddress = clientConnectionSocket.getInetAddress(); + localPort = clientConnectionSocket.getLocalPort(); + remotePort = clientConnectionSocket.getPort(); + + + + // My socket pair connection looks like this, to localhost: + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 )) + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) + // Why is the first IP/port the same, while the second set has different ports? + System.out.println("FisherServer socket pair showing host name, address, port:"); + System.out.println(" (( " + + localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( " + + remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))"); + + is = clientConnectionSocket.getInputStream(); + isr = new InputStreamReader(is); + br = new BufferedReader(isr); + + if (localAddress.getHostName().equals(localAddress.getHostAddress()) + || remoteAddress.getHostName().equals(remoteAddress.getHostAddress())) { + System.out.println(" note HostName matches address if host has no DNS name"); + } + + // Notice the use of flush() and try w/ resources. Without + // the try w/ resources the Socket object may stay open for + // a while after the client has stopped needing this + // connection. try w/ resources explicitly ends the connection. + serverLoopCount++; + ps.flush(); + // like it or not, you're outta here! + } + } + } catch (IOException e) { + System.err.println("Problem with FisherServer networking: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + } + +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Fisher/Homework_2_Event_Graph.pdf b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Fisher/Homework_2_Event_Graph.pdf new file mode 100644 index 0000000000000000000000000000000000000000..d4f2f7a2497d7b7652d2a3adb96212937e697836 Binary files /dev/null and b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Fisher/Homework_2_Event_Graph.pdf differ diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Fisher/Homework_2_Event_Graph.pptx b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Fisher/Homework_2_Event_Graph.pptx new file mode 100644 index 0000000000000000000000000000000000000000..149c22fae889fd01b20b709bc824e092980b6cbc Binary files /dev/null and b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Fisher/Homework_2_Event_Graph.pptx differ diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Fisher/Homework_2_Screenshot.png b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Fisher/Homework_2_Screenshot.png new file mode 100644 index 0000000000000000000000000000000000000000..fed97ba2a661bd59363c4e377859ee5dc9a4ac35 Binary files /dev/null and b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Fisher/Homework_2_Screenshot.png differ diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Leckie/LeckieClient.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Leckie/LeckieClient.java new file mode 100644 index 0000000000000000000000000000000000000000..3dac42ae73832877e0eeeb318db292023e0532af --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Leckie/LeckieClient.java @@ -0,0 +1,86 @@ +package MV3500Cohort2021JulySeptember.homework2.Leckie; +import java.io.*; +import java.net.*; + +/** + * + * @author Jacob Leckie + */ +public class LeckieClient { + + /** IPv6 String constant for localhost address, similarly IPv4 127.0.0.1 + * @see <a href="https://en.wikipedia.org/wiki/localhost">https://en.wikipedia.org/wiki/localhost</a> + * @see <a href="https://en.wikipedia.org/wiki/IPv6_address">https://en.wikipedia.org/wiki/IPv6_address</a> + */ + public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; + + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ + public static void main(String[] args) throws InterruptedException { + + // Local variables/fields + Socket socket = null; + InputStream is; + Reader isr; + BufferedReader br; + String serverMessage; + int clientLoopCount = 0; + + try { + while (true) + { + clientLoopCount++; // increment at beginning of loop for reliability + System.out.println(LeckieClient.class.getName() + " creating socket..."); + + // We request an IP to connect to ("localhost") and + // port number at that IP (2317). This establishes + // a connection to that IP in the form of a Socket + // object; the server uses a ServerSocket to wait for + // connections. + socket = new Socket(LOCALHOST, 2317); // locohost? + + // Now hook everything up (i.e. set up the streams), Java style: + is = socket.getInputStream(); + isr = new InputStreamReader(is); + br = new BufferedReader(isr); + + // Read a single line written by the server. We'd + // do things a bit differently if there were many lines to be read + // from the server instead of one only. + serverMessage = br.readLine(); + System.out.println("=================================================="); + +// System.out.print ("Client loop " + clientLoopCount + ": "); + System.out.println("I dont want to clean my room!"); + System.out.println("The message the server sent was: '" + serverMessage + "'"); + // socket gets closed, either automatically/silently by this code (or possibly by the server) + + Thread.sleep(500l); // slow things down, for example 500l (long) = 500 msec (1/2 second) + + } // end while(true) // infinite loops are dangerous, be sure to kill this process! + } + catch (IOException e) + { + System.err.println("Problem with " + LeckieClient.class.getName() + " networking:"); // describe what is happening + System.err.println("Error: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + finally // occurs after any other activity when shutting down + { + try { + if (socket != null) + socket.close(); + } catch (IOException e) {} + + // program exit: tell somebody about that happening. Likely cause: server drops connection. + System.out.println(); + System.out.println(LeckieClient.class.getName() + " exit"); + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Leckie/LeckieServer.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Leckie/LeckieServer.java new file mode 100644 index 0000000000000000000000000000000000000000..4b4ab8ea7087ccfaa687cbd4ae9fed1c69192ad4 --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Leckie/LeckieServer.java @@ -0,0 +1,88 @@ +package MV3500Cohort2021JulySeptember.homework2.Leckie; + +import java.io.*; +import java.net.*; + +/** + * + * @author Jacob Leckie + */ +public class LeckieServer { + + /** + * Program invocation, execution starts here + * If already compiled, can run using console in directory ../../build/classes/ by invoking \ + * java -classpath . TcpExamples.TcpExample3Server + * @param args command-line arguments + */ + public static void main(String[] args) { + try { + + // ServerSocket waits for a connection from a client. + // Notice that it is outside the loop; ServerSocket + // needs to be made only once. + System.out.println(LeckieServer.class.getName() + " has started..."); // it helps debugging to put this on console first + + ServerSocket serverSocket = new ServerSocket(2317); + OutputStream os; + PrintStream ps; + InetAddress localAddress, remoteAddress; + int localPort, remotePort; + int serverLoopCount = 0; + + // Server is up and waiting (i.e. "blocked" or paused) + // Loop, infinitely, waiting for client connections. + // Stop the program somewhere else. + while (true) { + + // block until connected to a client + try (Socket clientConnectionSocket = serverSocket.accept()) + { + serverLoopCount++; // increment at beginning of loop for reliability + + // Now hook everything up (i.e. set up the streams), Java style: + os = clientConnectionSocket.getOutputStream(); + ps = new PrintStream(os); + ps.println("I told you " + serverLoopCount + " time, go clean your room!"); // this gets sent back to client! + + // Print some information locally about the Socket connection. + // This includes the port and IP numbers on both sides (the socket pair). + localAddress = clientConnectionSocket.getLocalAddress(); + remoteAddress = clientConnectionSocket.getInetAddress(); + localPort = clientConnectionSocket.getLocalPort(); + remotePort = clientConnectionSocket.getPort(); + + System.out.print ("Server loop " + serverLoopCount + ": "); + + // My socket pair connection looks like this, to localhost: + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 )) + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) + + // Why is the first IP/port the same, while the second set has different ports? + System.out.println(LeckieServer.class.getName() + " socket pair showing host name, address, port:"); + System.out.println(" (( " + + localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( " + + remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))"); + + if ( localAddress.getHostName().equals( localAddress.getHostAddress()) || + remoteAddress.getHostName().equals(remoteAddress.getHostAddress())) + System.out.println(" note HostName matches address if host has no DNS name"); + + // Notice the use of flush() and try w/ resources. Without + // the try w/ resources the Socket object may stay open for + // a while after the client has stopped needing this + // connection. try w/ resources explicitly ends the connection. + ps.flush(); + // like it or not, you're outta here! + } + } + } catch (IOException e) { + System.err.println("Problem with " + LeckieServer.class.getName() + " networking: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/McNeely/McNeelyTCPExample3Client.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/McNeely/McNeelyTCPExample3Client.java new file mode 100644 index 0000000000000000000000000000000000000000..8e495a0b9649ac5266259d5ba73a5546a2d054b0 --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/McNeely/McNeelyTCPExample3Client.java @@ -0,0 +1,93 @@ +package MV3500Cohort2021JulySeptember.homework2.McNeely; + +import java.io.*; +import java.net.*; + +/** + * Before, we always used telnet (netcat) to connect to the server. Here we are + * now writing our own program to do the connection. + * + * As you will see, when we run this after we start the server we will see the + * same string telnet printed, sent by the server. The output at the server will + * show different socket pairs for each time the loop iterates. + * + * @author jrm_u + */ +public class McNeelyTCPExample3Client { + + /** IPv6 String constant for localhost address, similarly IPv4 127.0.0.1 + * @see <a href="https://en.wikipedia.org/wiki/localhost">https://en.wikipedia.org/wiki/localhost</a> + * @see <a href="https://en.wikipedia.org/wiki/IPv6_address">https://en.wikipedia.org/wiki/IPv6_address</a> + */ + public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; + + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ + public static void main(String[] args) throws InterruptedException { + + // Local variables/fields + Socket socket = null; + InputStream is; + Reader isr; + BufferedReader br; + String serverMessage; + int clientLoopCount = 0; + + try { + while (true) + { + clientLoopCount++; // increment at beginning of loop for reliability + System.out.println(McNeelyTCPExample3Client.class.getName() + "McNeely creating socket..."); + + // We request an IP to connect to ("localhost") and + // port number at that IP (2317). This establishes + // a connection to that IP in the form of a Socket + // object; the server uses a ServerSocket to wait for + // connections. + socket = new Socket(LOCALHOST, 2317); // locohost? + + // Now hook everything up (i.e. set up the streams), Java style: + is = socket.getInputStream(); + isr = new InputStreamReader(is); + br = new BufferedReader(isr); + + // Read a single line written by the server. We'd + // do things a bit differently if there were many lines to be read + // from the server instead of one only. + serverMessage = br.readLine(); + System.out.println("=================================================="); + + System.out.print ("Client loop " + clientLoopCount + ": "); + System.out.println("now we're cooking with diesel fuel!"); + System.out.println("The message the server sent was: '" + serverMessage + "'"); + // socket gets closed, either automatically/silently by this code (or possibly by the server) + + Thread.sleep(500l); // slow things down, for example 500l (long) = 500 msec + + } // end while(true) // infinite loops are dangerous, be sure to kill this process! + } + catch (IOException e) + { + System.err.println("Problem with " + McNeelyTCPExample3Client.class.getName() + " networking:"); // describe what is happening + System.err.println("Error: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + finally // occurs after any other activity when shutting down + { + try { + if (socket != null) + socket.close(); + } catch (IOException e) {} + + // program exit: tell somebody about that happening. Likely cause: server drops connection. + System.out.println(); + System.out.println(McNeelyTCPExample3Client.class.getName() + " exit"); + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/McNeely/McNeelyTCPExample3Server.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/McNeely/McNeelyTCPExample3Server.java new file mode 100644 index 0000000000000000000000000000000000000000..c1b312f2008c6033a0eabb3c1f30e953f3089771 --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/McNeely/McNeelyTCPExample3Server.java @@ -0,0 +1,102 @@ +package MV3500Cohort2021JulySeptember.homework2.McNeely; + +import java.io.*; +import java.net.*; + +/** + * Very slightly more complex than example1, further modifying example2. The + * only thing this does differently is introduce a loop into the response, so + * you don't have to restart the program after one response. Also, it prints out + * the socket pair the server sees. Run the program via telnet several times and + * compare the socket pairs. + * + * telnet (nc) localhost 2317 + * + * If you're sophisticated you can contact the instructor's computer while + * running this program. + * + * telnet (nc) [ipNumberOfServerLaptop] 2317 + * + * and have the instructor display the socket pairs received. + * + * @author jrm_u + */ +public class McNeelyTCPExample3Server { + + /** + * Program invocation, execution starts here + * If already compiled, can run using console in directory ../../build/classes/ by invoking \ + * java -classpath . TcpExamples.TcpExample3Server + * @param args command-line arguments + */ + public static void main(String[] args) { + try { + + // ServerSocket waits for a connection from a client. + // Notice that it is outside the loop; ServerSocket + // needs to be made only once. + System.out.println(McNeelyTCPExample3Server.class.getName() + " has started... here we go!"); // it helps debugging to put this on console first + + ServerSocket serverSocket = new ServerSocket(2317); + OutputStream os; + PrintStream ps; + InetAddress localAddress, remoteAddress; + int localPort, remotePort; + int serverLoopCount = 0; + + // Server is up and waiting (i.e. "blocked" or paused) + // Loop, infinitely, waiting for client connections. + // Stop the program somewhere else. + while (true) { + + // block until connected to a client + try (Socket clientConnectionSocket = serverSocket.accept()) + { + serverLoopCount++; // increment at beginning of loop for reliability + + // Now hook everything up (i.e. set up the streams), Java style: + os = clientConnectionSocket.getOutputStream(); + ps = new PrintStream(os); + ps.println("This is response number " + serverLoopCount + " produced by Justin's server."); // this gets sent back to client! + + // Print some information locally about the Socket connection. + // This includes the port and IP numbers on both sides (the socket pair). + localAddress = clientConnectionSocket.getLocalAddress(); + remoteAddress = clientConnectionSocket.getInetAddress(); + localPort = clientConnectionSocket.getLocalPort(); + remotePort = clientConnectionSocket.getPort(); + + System.out.print ("Server loop " + serverLoopCount + ": "); + + // My socket pair connection looks like this, to localhost: + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 )) + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) + + // Why is the first IP/port the same, while the second set has different ports? + System.out.println(McNeelyTCPExample3Server.class.getName() + " socket pair showing host name, address, port:"); + System.out.println(" (( " + + localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( " + + remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))"); + + if ( localAddress.getHostName().equals( localAddress.getHostAddress()) || + remoteAddress.getHostName().equals(remoteAddress.getHostAddress())) + System.out.println(" note HostName matches address if host has no DNS name"); + + // Notice the use of flush() and try w/ resources. Without + // the try w/ resources the Socket object may stay open for + // a while after the client has stopped needing this + // connection. try w/ resources explicitly ends the connection. + ps.flush(); + // like it or not, you're outta here! + } + } + } catch (IOException e) { + System.err.println("Problem with " + McNeelyTCPExample3Server.class.getName() + " networking: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Morris/MorrisTCPExample3Client.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Morris/MorrisTCPExample3Client.java new file mode 100644 index 0000000000000000000000000000000000000000..1eb66d23a88cb5160dba541a39bb75dd06e608df --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Morris/MorrisTCPExample3Client.java @@ -0,0 +1,94 @@ + + +package MV3500Cohort2021JulySeptember.homework2.Morris; + +import java.io.*; +import java.net.*; + +/** + * + * @author johnmorris + */ +public class MorrisTCPExample3Client { + + + + + /** IPv6 String constant for localhost address, similarly IPv4 127.0.0.1 + * @see <a href="https://en.wikipedia.org/wiki/localhost">https://en.wikipedia.org/wiki/localhost</a> + * @see <a href="https://en.wikipedia.org/wiki/IPv6_address">https://en.wikipedia.org/wiki/IPv6_address</a> + */ + public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; + + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ + public static void main(String[] args) throws InterruptedException { + + // Local variables/fields + Socket socket = null; + InputStream is; + Reader isr; + BufferedReader br; + String serverMessage; + int clientLoopCount = 0; + + try { + while (true) + { + clientLoopCount++; // increment at beginning of loop for reliability + System.out.println(MorrisTCPExample3Client.class.getName() + " creating socket..."); + + // We request an IP to connect to ("localhost") and + // port number at that IP (2317). This establishes + // a connection to that IP in the form of a Socket + // object; the server uses a ServerSocket to wait for + // connections. + socket = new Socket(LOCALHOST, 2317); // locohost? + + // Now hook everything up (i.e. set up the streams), Java style: + is = socket.getInputStream(); + isr = new InputStreamReader(is); + br = new BufferedReader(isr); + + // Read a single line written by the server. We'd + // do things a bit differently if there were many lines to be read + // from the server instead of one only. + serverMessage = br.readLine(); + System.out.println("Half Way Thru Quarter"); + + System.out.print ("Client loop " + clientLoopCount + ": "); + System.out.println("now we can coordinate weekend Party!"); + System.out.println("The message the server sent was: '" + serverMessage + "'"); + // socket gets closed, either automatically/silently by this code (or possibly by the server) + + Thread.sleep(500l); // slow things down, for example 500l (long) = 500 msec (1/2 second) + + } // end while(true) // infinite loops are dangerous, be sure to kill this process! + } + catch (IOException e) + { + System.err.println("Problem with " + MorrisTCPExample3Client.class.getName() + " networking:"); // describe what is happening + System.err.println("Error: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + finally // occurs after any other activity when shutting down + { + try { + if (socket != null) + socket.close(); + } catch (IOException e) {} + + // program exit: tell somebody about that happening. Likely cause: server drops connection. + System.out.println(); + System.out.println(MorrisTCPExample3Client.class.getName() + " exit"); + } + } +} + + diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Morris/MorrisTcpExample3Server.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Morris/MorrisTcpExample3Server.java new file mode 100644 index 0000000000000000000000000000000000000000..8c2d7155a4c86034a2a789c8e80e29aee60303da --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Morris/MorrisTcpExample3Server.java @@ -0,0 +1,104 @@ + +package MV3500Cohort2021JulySeptember.homework2.Morris; + +import java.io.*; +import java.net.*; + +/** + * Very slightly more complex than example1, further modifying example2. The + * only thing this does differently is introduce a loop into the response, so + * you don't have to restart the program after one response. Also, it prints out + * the socket pair the server sees. Run the program via telnet several times and + * compare the socket pairs. + * + * telnet (nc) localhost 2317 + * + * If you're sophisticated you can contact the instructor's computer while + * running this program. + * + * telnet (nc) [ipNumberOfServerLaptop] 2317 + * + * and have the instructor display the socket pairs received. + * + * @author mcgredo + * + */ +public class MorrisTcpExample3Server { + + /** + * Program invocation, execution starts here + * If already compiled, can run using console in directory ../../build/classes/ by invoking \ + * java -classpath . TcpExamples.TcpExample3Server + * @param args command-line arguments + */ + public static void main(String[] args) { + try { + + // ServerSocket waits for a connection from a client. + // Notice that it is outside the loop; ServerSocket + // needs to be made only once. + System.out.println(MorrisTcpExample3Server.class.getName() + " is rolling..."); // it helps debugging to put this on console first + + ServerSocket serverSocket = new ServerSocket(2317); + OutputStream os; + PrintStream ps; + InetAddress localAddress, remoteAddress; + int localPort, remotePort; + int serverLoopCount = 0; + + // Server is up and waiting (i.e. "blocked" or paused) + // Loop, infinitely, waiting for client connections. + // Stop the program somewhere else. + while (true) { + + // block until connected to a client + try (Socket clientConnectionSocket = serverSocket.accept()) + { + serverLoopCount++; // increment at beginning of loop for reliability + + // Now hook everything up (i.e. set up the streams), Java style: + os = clientConnectionSocket.getOutputStream(); + ps = new PrintStream(os); + ps.println("This is response " + serverLoopCount + " produced by the Morris server."); // this gets sent back to client! + + // Print some information locally about the Socket connection. + // This includes the port and IP numbers on both sides (the socket pair). + localAddress = clientConnectionSocket.getLocalAddress(); + remoteAddress = clientConnectionSocket.getInetAddress(); + localPort = clientConnectionSocket.getLocalPort(); + remotePort = clientConnectionSocket.getPort(); + + System.out.print ("Server loop " + serverLoopCount + ": "); + + // My socket pair connection looks like this, to localhost: + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 )) + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) + + // Why is the first IP/port the same, while the second set has different ports? + System.out.println(MorrisTcpExample3Server.class.getName() + " socket pair showing host name, address, port:"); + System.out.println(" (( " + + localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( " + + remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))"); + + if ( localAddress.getHostName().equals( localAddress.getHostAddress()) || + remoteAddress.getHostName().equals(remoteAddress.getHostAddress())) + System.out.println(" note HostName matches address if host has no DNS name"); + + // Notice the use of flush() and try w/ resources. Without + // the try w/ resources the Socket object may stay open for + // a while after the client has stopped needing this + // connection. try w/ resources explicitly ends the connection. + ps.flush(); + // like it or not, you're outta here! + } + } + } catch (IOException e) { + System.err.println("Problem with " + MorrisTcpExample3Server.class.getName() + " networking: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Morris/Screen_Shot_2021-08-06_at_10.27.59_AM.png b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Morris/Screen_Shot_2021-08-06_at_10.27.59_AM.png new file mode 100644 index 0000000000000000000000000000000000000000..c8ffd08013debb2e34b50629d28e6d0f87753025 Binary files /dev/null and b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Morris/Screen_Shot_2021-08-06_at_10.27.59_AM.png differ diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Morris/UML_HW_2_Morris.pdf b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Morris/UML_HW_2_Morris.pdf new file mode 100644 index 0000000000000000000000000000000000000000..ab86233ebe4479d48ba8e78d4190269c1ffa2a1e Binary files /dev/null and b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Morris/UML_HW_2_Morris.pdf differ diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Morris/UML_HW_2_Morris.pptx b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Morris/UML_HW_2_Morris.pptx new file mode 100644 index 0000000000000000000000000000000000000000..a681d1132d9f87a3a9fbd9d5a0c44408cc1a1171 Binary files /dev/null and b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Morris/UML_HW_2_Morris.pptx differ diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/ReynoldsTcpExample3Client.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/ReynoldsTcpExample3Client.java new file mode 100644 index 0000000000000000000000000000000000000000..7d5dbec55a350f8ac33103692a6c7f93abd7d2fe --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/ReynoldsTcpExample3Client.java @@ -0,0 +1,95 @@ +package MV3500Cohort2021JulySeptember.homework2; + +import java.io.*; +import java.net.*; + +/** + * Before, we always used telnet (netcat) to connect to the server. Here we are + * now writing our own program to do the connection. + * + * As you will see, when we run this after we start the server we will see the + * same string telnet printed, sent by the server. The output at the server will + * show different socket pairs for each time the loop iterates. + * + * @author mcgredo + * @author brutzman + * @author reynolds + */ +public class ReynoldsTcpExample3Client { + + /** IPv6 String constant for localhost address, similarly IPv4 127.0.0.1 + * @see <a href="https://en.wikipedia.org/wiki/localhost">https://en.wikipedia.org/wiki/localhost</a> + * @see <a href="https://en.wikipedia.org/wiki/IPv6_address">https://en.wikipedia.org/wiki/IPv6_address</a> + */ + public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; + + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ + public static void main(String[] args) throws InterruptedException { + + // Local variables/fields + Socket socket = null; + InputStream is; + Reader isr; + BufferedReader br; + String serverMessage; + int clientLoopCount = 0; + + try { + while (true) + { + clientLoopCount++; // increment at beginning of loop for reliability + System.out.println(ReynoldsTcpExample3Client.class.getName() + " looking for an empire to join..."); + + // We request an IP to connect to ("localhost") and + // port number at that IP (2317). This establishes + // a connection to that IP in the form of a Socket + // object; the server uses a ServerSocket to wait for + // connections. + socket = new Socket(LOCALHOST, 2317); // locohost? + + // Now hook everything up (i.e. set up the streams), Java style: + is = socket.getInputStream(); + isr = new InputStreamReader(is); + br = new BufferedReader(isr); + + // Read a single line written by the server. We'd + // do things a bit differently if there were many lines to be read + // from the server instead of one only. + serverMessage = br.readLine(); + System.out.println("=================================================="); + + System.out.print ("Client # " + clientLoopCount + ": "); + System.out.println("I've sided with the empire!"); + System.out.println("The the serverlord has spoken... it said: '" + serverMessage + "' \n" ); + // socket gets closed, either automatically/silently by this code (or possibly by the server) + + Thread.sleep(500l); // slow things down, for example 500l (long) = 500 msec + + } // end while(true) // infinite loops are dangerous, be sure to kill this process! + } + catch (IOException e) + { + System.err.println("Problem with " + ReynoldsTcpExample3Client.class.getName() + " networking:"); // describe what is happening + System.err.println("Error: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + finally // occurs after any other activity when shutting down + { + try { + if (socket != null) + socket.close(); + } catch (IOException e) {} + + // program exit: tell somebody about that happening. Likely cause: server drops connection. + System.out.println(); + System.out.println(ReynoldsTcpExample3Client.class.getName() + " exit"); + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/ReynoldsTcpExample3Server.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/ReynoldsTcpExample3Server.java new file mode 100644 index 0000000000000000000000000000000000000000..f56e658ebdb33b6c5d00f5ad7b3e96a16511ad10 --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/ReynoldsTcpExample3Server.java @@ -0,0 +1,104 @@ +package MV3500Cohort2021JulySeptember.homework2; + +import java.io.*; +import java.net.*; + +/** + * Very slightly more complex than example1, further modifying example2. The + * only thing this does differently is introduce a loop into the response, so + * you don't have to restart the program after one response. Also, it prints out + * the socket pair the server sees. Run the program via telnet several times and + * compare the socket pairs. + * + * telnet (nc) localhost 2317 + * + * If you're sophisticated you can contact the instructor's computer while + * running this program. + * + * telnet (nc) [ipNumberOfServerLaptop] 2317 + * + * and have the instructor display the socket pairs received. + * + * @author mcgredo + * @author brutzman + * @author reynolds + */ +public class ReynoldsTcpExample3Server { + + /** + * Program invocation, execution starts here + * If already compiled, can run using console in directory ../../build/classes/ by invoking \ + * java -classpath . TcpExamples.TcpExample3Server + * @param args command-line arguments + */ + public static void main(String[] args) { + try { + + // ServerSocket waits for a connection from a client. + // Notice that it is outside the loop; ServerSocket + // needs to be made only once. + System.out.println(ReynoldsTcpExample3Server.class.getName() + " has started hosting, looking for a new client to pad my empire..."); // it helps debugging to put this on console first + + ServerSocket serverSocket = new ServerSocket(2317); + OutputStream os; + PrintStream ps; + InetAddress localAddress, remoteAddress; + int localPort, remotePort; + int serverLoopCount = 0; + + // Server is up and waiting (i.e. "blocked" or paused) + // Loop, infinitely, waiting for client connections. + // Stop the program somewhere else. + while (true) { + + // block until connected to a client + try (Socket clientConnectionSocket = serverSocket.accept()) + { + serverLoopCount++; // increment at beginning of loop for reliability + + // Now hook everything up (i.e. set up the streams), Java style: + os = clientConnectionSocket.getOutputStream(); + ps = new PrintStream(os); + ps.println("Thank you client " + serverLoopCount + ", you have added to my growing empire!"); // this gets sent back to client! + + // Print some information locally about the Socket connection. + // This includes the port and IP numbers on both sides (the socket pair). + localAddress = clientConnectionSocket.getLocalAddress(); + remoteAddress = clientConnectionSocket.getInetAddress(); + localPort = clientConnectionSocket.getLocalPort(); + remotePort = clientConnectionSocket.getPort(); + + System.out.print ("Server loop " + serverLoopCount + ": "); + + // My socket pair connection looks like this, to localhost: + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 )) + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) + + // Why is the first IP/port the same, while the second set has different ports? + System.out.println(ReynoldsTcpExample3Server.class.getName() + " socket pair showing host name, address, port:"); + System.out.println(" (( " + + localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( " + + remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))"); + + if ( localAddress.getHostName().equals( localAddress.getHostAddress()) || + remoteAddress.getHostName().equals(remoteAddress.getHostAddress())) + System.out.println(" note HostName matches address if host has no DNS name"); + + // Notice the use of flush() and try w/ resources. Without + // the try w/ resources the Socket object may stay open for + // a while after the client has stopped needing this + // connection. try w/ resources explicitly ends the connection. + ps.flush(); + // like it or not, you're outta here! + } + } + } catch (IOException e) { + System.err.println("Problem with " + ReynoldsTcpExample3Server.class.getName() + " networking: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + } +} diff --git a/examples/src/OpenDis7Examples/images/Example4SequenceDiagram.png b/examples/src/OpenDis7Examples/images/Example4SequenceDiagram.png deleted file mode 100644 index 3eb3a8e753d2e7aea1baf4a1366b06397446f829..0000000000000000000000000000000000000000 Binary files a/examples/src/OpenDis7Examples/images/Example4SequenceDiagram.png and /dev/null differ diff --git a/examples/src/OpenDis7ExamplesAllPduScreenCapture.png b/examples/src/OpenDis7Examples/images/OpenDis7ExamplesAllPduScreenCapture.png similarity index 100% rename from examples/src/OpenDis7ExamplesAllPduScreenCapture.png rename to examples/src/OpenDis7Examples/images/OpenDis7ExamplesAllPduScreenCapture.png diff --git a/examples/src/TcpExamples/TcpExample2ConnectionCounting.java b/examples/src/TcpExamples/TcpExample2ConnectionCounting.java index 3b99cfa68f3a0fed2c85be70edf23cf7b71843f5..c1b62609c7d5c46014b06f0ce7db5b8f24e36be9 100644 --- a/examples/src/TcpExamples/TcpExample2ConnectionCounting.java +++ b/examples/src/TcpExamples/TcpExample2ConnectionCounting.java @@ -36,7 +36,7 @@ public class TcpExample2ConnectionCounting System.out.println(" Windows ipconfig (or Mac ifconfig) indicates current IPv4_Address (for example local wireless IP address)"); System.out.println(" Windows enter (telnet localhost 2317) or Mac enter (nc localhost 2317) for loopback operation, or" ); System.out.println(" Windows enter (telnet IPv4_Address 2317) or Mac enter (nc IPv4_Address 2317) for LAN operation" ); - System.out.println("TcpExample2ConnectionCounting server standing by..." ); + System.out.println("TcpExample2ConnectionCounting server standing by..." ); // ServerSocket waits for a connection from a client. // Notice that it is outside the loop; ServerSocket needs to be made only once. diff --git a/examples/src/TcpExamples/TcpExample3Client.java b/examples/src/TcpExamples/TcpExample3Client.java index 2151b5fc37ab3f356cbc014575a1a9a4dfe09de7..9d1fe38c29b76dd970327eb7744ec5803aab4dfa 100644 --- a/examples/src/TcpExamples/TcpExample3Client.java +++ b/examples/src/TcpExamples/TcpExample3Client.java @@ -47,7 +47,7 @@ public class TcpExample3Client { // a connection to that IP in the form of a Socket // object; the server uses a ServerSocket to wait for // connections. - socket = new Socket(LOCALHOST, 2317); // locohost? + socket = new Socket(LOCALHOST, 2317); // locohost? // Now hook everything up (i.e. set up the streams), Java style: is = socket.getInputStream(); @@ -65,7 +65,7 @@ public class TcpExample3Client { System.out.println("The message the server sent was: '" + serverMessage + "'"); // socket gets closed, either automatically/silently by this code (or possibly by the server) - Thread.sleep(500l); // slow things down, for example 500l (long) = 500 msec + Thread.sleep(500l); // slow things down, for example 500l (long) = 500 msec (1/2 second) } // end while(true) // infinite loops are dangerous, be sure to kill this process! } diff --git a/examples/src/TcpExamples/TcpExample4SequenceDiagram.png b/examples/src/TcpExamples/TcpExample4SequenceDiagram.png index 12e6378d530803907f66ea638b8844fdc116dded..3eb3a8e753d2e7aea1baf4a1366b06397446f829 100644 Binary files a/examples/src/TcpExamples/TcpExample4SequenceDiagram.png and b/examples/src/TcpExamples/TcpExample4SequenceDiagram.png differ diff --git a/examples/src/OpenDis7Examples/images/Example4SequenceDiagram.vsdx b/examples/src/TcpExamples/TcpExample4SequenceDiagram.vsdx similarity index 100% rename from examples/src/OpenDis7Examples/images/Example4SequenceDiagram.vsdx rename to examples/src/TcpExamples/TcpExample4SequenceDiagram.vsdx diff --git a/examples/src/OpenDis7Examples/images/Example4SequenceDrawing.png b/examples/src/TcpExamples/TcpExample4SequenceSketch.png similarity index 100% rename from examples/src/OpenDis7Examples/images/Example4SequenceDrawing.png rename to examples/src/TcpExamples/TcpExample4SequenceSketch.png diff --git a/presentations/04_TCPSocketsJava.pptx b/presentations/04_TCPSocketsJava.pptx index 19ab33d24b7c6200f38a75bb4c57db5d3268381f..23ca879f0de227bc27de42d6138ed38860fa7b5c 100644 Binary files a/presentations/04_TCPSocketsJava.pptx and b/presentations/04_TCPSocketsJava.pptx differ diff --git a/specifications/build.xml b/specifications/build.xml index 0c9d87fa2333bc7da87e0c064ee2d76b79c2b216..88bd1d6f7479af083ce5d0ba2a53a21ff2ea7366 100644 --- a/specifications/build.xml +++ b/specifications/build.xml @@ -2,6 +2,22 @@ <project name="Download IEEE and SISO Specifications" default="download.all" basedir="."> <target name="download.all" depends="download.clean.specifications,download.SISO,download.IeeeDisStandards.instructions"/> + + <property name="DIS.1.document" value="6387564"/> + <property name="DIS.1.rename" value="IEEE1278.1-2012.DistributedInteractiveSimulation.ApplicationProtocols.${DIS.1.document}.pdf"/> + <property name="DIS.1.title" value="1278.1-2012 - IEEE Standard for Distributed Interactive Simulation (DIS) -- Application Protocols"/> + + <property name="DIS.2.document" value="7459689"/> + <property name="DIS.2.rename" value="IEEE1278.2-2015.DistributedInteractiveSimulation.CommunicationsServices.${DIS.2.document}.pdf.SAVEME"/> + <property name="DIS.2.title" value="1278.2-2015 - IEEE Standard for Distributed Interactive Simulation (DIS) -- Communication Services and Profiles"/> + + <property name="DIS.3.document" value="587529"/> + <property name="DIS.3.rename" value="IEEE1278.3-2015.DistributedInteractiveSimulation.CommunicationsServices.${DIS.3.document}.pdf.SAVEME"/> + <property name="DIS.3.title" value="1278.3-1996 - IEEE Recommended Practice for Distributed Interactive Simulation (DIS) -- Exercise Management and Feedback"/> + + <property name="DIS.4.document" value="8685803"/> + <property name="DIS.4.rename" value="IEEE1278.4-1997.DistributedInteractiveSimulation.VV+A.${DIS.4.document}.pdf.SAVEME"/> + <property name="DIS.4.title" value="1278.4-1997 - IEEE Recommended Practice for Distributed Interactive Simulation (DIS) -- Verification, Validation, and Accreditation (VV+A)"/> <target name="download.clean.specifications"> <echo message="ensure all files are closed before deleting..."/> @@ -25,18 +41,25 @@ <!-- =============================================== --> <target name="download.IeeeDisStandards.rename" description="rename saved DIS specification files to readable filenames"> + <!-- move files to subdirectory if needed --> + <move file="12781-2012.pdf" todir="downloads/" failonerror="false"/> + <move file="12782-2015.pdf" todir="downloads/" failonerror="false"/> + <move file="00587529.pdf" todir="downloads/" failonerror="false"/> + <move file="12784-1997.pdf" todir="downloads/" failonerror="false"/> <!-- part 1 6387564.pdf --> - <move file="12781-2012.pdf" tofile="IEEE1278.1-2012.DistributedInteractiveSimulation.ApplicationProtocols.12781-2012.pdf" verbose="true" quiet="true" failonerror="false"/> - <copy todir="archive" file="IEEE1278.1-2012.DistributedInteractiveSimulation.ApplicationProtocols.12781-2012.pdf" verbose="true" quiet="true" failonerror="false"/> + <move file="downloads/12781-2012.pdf" tofile="downloads/IEEE1278.1-2012.DistributedInteractiveSimulation.ApplicationProtocols.12781-2012.pdf" verbose="true" quiet="true" failonerror="false"/> <!-- part 2 7459689.pdf --> - <move file="12782-2015.pdf" tofile="IEEE1278.2-2015.DistributedInteractiveSimulation.CommunicationsServices.12782-2015.pdf" verbose="true" quiet="true" failonerror="false"/> - <copy todir="archive" file="IEEE1278.2-2015.DistributedInteractiveSimulation.CommunicationsServices.12782-2015.pdf" verbose="true" quiet="true" failonerror="false"/> + <move file="downloads/12782-2015.pdf" tofile="downloads/IEEE1278.2-2015.DistributedInteractiveSimulation.CommunicationsServices.12782-2015.pdf" verbose="true" quiet="true" failonerror="false"/> <!-- part 3 00587529.pdf --> - <move file= "00587529.pdf" tofile="IEEE1278.3-2015.DistributedInteractiveSimulation.CommunicationsServices.00587529.pdf" verbose="true" quiet="true" failonerror="false"/> - <copy todir="archive" file="IEEE1278.3-2015.DistributedInteractiveSimulation.CommunicationsServices.00587529.pdf" verbose="true" quiet="true" failonerror="false"/> + <move file= "downloads/00587529.pdf" tofile="downloads/IEEE1278.3-2015.DistributedInteractiveSimulation.CommunicationsServices.00587529.pdf" verbose="true" quiet="true" failonerror="false"/> <!-- part 4 6595010.pdf --> - <move file="12784-1997.pdf" tofile="IEEE1278.4-2013.DistributedInteractiveSimulation.VV+A.12784-1997.pdf" verbose="true" quiet="true" failonerror="false"/> - <copy todir="archive" file="IEEE1278.4-2013.DistributedInteractiveSimulation.VV+A.12784-1997.pdf" verbose="true" quiet="true" failonerror="false"/> + <move file="downloads/12784-1997.pdf" tofile="downloads/IEEE1278.4-2013.DistributedInteractiveSimulation.VV+A.12784-1997.pdf" verbose="true" quiet="true" failonerror="false"/> + <!-- + <copy todir="downloads" file="IEEE1278.1-2012.DistributedInteractiveSimulation.ApplicationProtocols.12781-2012.pdf" verbose="true" quiet="true" failonerror="false"/> + <copy todir="downloads" file="IEEE1278.2-2015.DistributedInteractiveSimulation.CommunicationsServices.12782-2015.pdf" verbose="true" quiet="true" failonerror="false"/> + <copy todir="downloads" file="IEEE1278.3-2015.DistributedInteractiveSimulation.CommunicationsServices.00587529.pdf" verbose="true" quiet="true" failonerror="false"/> + <copy todir="downloads" file="IEEE1278.4-2013.DistributedInteractiveSimulation.VV+A.12784-1997.pdf" verbose="true" quiet="true" failonerror="false"/> + --> <echo message="check *.pdf directory contents..."/> <!-- https://stackoverflow.com/questions/10528032/listing-all-files-and-subdirectories-using-ant --> @@ -45,11 +68,11 @@ <!-- https://stackoverflow.com/questions/7102793/how-to-put-a-newline-in-ant-property --> <echo message="specifications directory:"/> <echo message="${prop.dist.contents}"/> - <fileset id="archive.contents" dir="archive" includes="*.pdf"/> - <property name="prop.archive.contents" refid="archive.contents"/> + <fileset id="downloads.contents" dir="downloads" includes="*.pdf"/> + <property name="prop.downloads.contents" refid="downloads.contents"/> <!-- https://stackoverflow.com/questions/7102793/how-to-put-a-newline-in-ant-property --> - <echo message="specifications/archive directory:"/> - <echo message="${prop.archive.contents}"/> + <echo message="specifications/downloads directory:"/> + <echo message="${prop.downloads.contents}"/> </target> <!-- =============================================== --> @@ -63,58 +86,60 @@ <echo message="Warning: due to cookie and scripting restrictions, you must download IEEE specifications manually via links found in README.md"/> <echo message="TODO: university students/faculty can first login with permissions to the IEEE Explore page, then use target download.IeeeDisStandards.retrieve"/> <echo message="IEEE Explore: ${ieeeExploreUrl}"/> + <echo/> <!-- ======================== --> - <property name="DIS.1.document" value="6387564"/> - <property name="DIS.1.rename" value="IEEE1278.1-2012.DistributedInteractiveSimulation.ApplicationProtocols.${DIS.1.document}.pdf"/> - <echo message="see ${ieeeBasePageUrl}${DIS.1.document}"/> + <echo message="${DIS.1.title}"/> + <echo message="see ${ieeeBasePageUrl}${DIS.1.document}"/> <echo message="get ${ieeeBaseLinkUrl}${DIS.1.document}"/> + <echo message="to downloads/ subdirectory"/> <echo message="as ${DIS.1.rename}"/> <!-- <get src="${ieeeBaseLinkUrl}${DIS.1.document}" - dest="${DIS.1.rename}" verbose="true"/> --> + dest="downloads/${DIS.1.rename}" verbose="true"/> --> <property name="warningMessage" value="Restriction: cookie restrictions prevent automated download. You must manually download this file while within NPS campus or firewall. For "/> <echo message="${warningMessage}IEEE1278.1 retrieval to this location, use your browser to save ${ieeeBaseLinkUrl}${DIS.1.document}" file="${DIS.1.rename}.SAVEME"/> - <echo message=""/> + <echo/> <!-- ======================== --> - <property name="DIS.2.document" value="7459689"/> - <property name="DIS.2.rename" value="IEEE1278.2-2015.DistributedInteractiveSimulation.CommunicationsServices.${DIS.2.document}.pdf.SAVEME"/> - <echo message="see ${ieeeBasePageUrl}${DIS.2.document}"/> + <echo message="${DIS.2.title}"/> + <echo message="see ${ieeeBasePageUrl}${DIS.2.document}"/> <echo message="get ${ieeeBaseLinkUrl}${DIS.2.document}"/> + <echo message="to downloads/ subdirectory"/> <echo message="as ${DIS.2.rename}"/> <!-- <get src="${ieeeBaseLinkUrl}${DIS.2.document}" - dest="${DIS.2.rename}" verbose="true"/> --> + dest="downloads/${DIS.2.rename}" verbose="true"/> --> <echo message="${warningMessage}IEEE1278.2 retrieval to this location, use your browser to save ${ieeeBaseLinkUrl}${DIS.2.document}" file="${DIS.2.rename}"/> - <echo message=""/> + <echo/> <!-- ======================== --> - <property name="DIS.3.document" value="587529"/> - <property name="DIS.3.rename" value="IEEE1278.3-2015.DistributedInteractiveSimulation.CommunicationsServices.${DIS.3.document}.pdf.SAVEME"/> - <echo message="see ${ieeeBasePageUrl}${DIS.3.document}"/> + <echo message="${DIS.3.title}"/> + <echo message="see ${ieeeBasePageUrl}${DIS.3.document}"/> <echo message="get ${ieeeBaseLinkUrl}${DIS.3.document}"/> + <echo message="to downloads/ subdirectory"/> <echo message="as ${DIS.3.rename}"/> <!-- <get src="${ieeeBaseLinkUrl}${DIS.3.document}" - dest="${DIS.3.rename}" verbose="true"/> --> + dest="downloads/${DIS.3.rename}" verbose="true"/> --> <echo message="${warningMessage}IEEE1278.3 retrieval to this location, use your browser to save ${ieeeBaseLinkUrl}${DIS.3.document}" file="${DIS.3.rename}"/> - <echo message=""/> + <echo/> <!-- ======================== --> - <property name="DIS.4.document" value="8685803"/> - <property name="DIS.4.rename" value="IEEE1278.4-2013.DistributedInteractiveSimulation.VV+A.${DIS.4.document}.pdf.SAVEME"/> - <echo message="see ${ieeeBasePageUrl}${DIS.4.document}"/> + <echo message="${DIS.4.title}"/> + <echo message="see ${ieeeBasePageUrl}${DIS.4.document}"/> <echo message="get ${ieeeBaseLinkUrl}${DIS.4.document}"/> + <echo message="to downloads/ subdirectory"/> <echo message="as ${DIS.4.rename}"/> <!-- <get src="${ieeeBaseLinkUrl}${DIS.4.document}" - dest="${DIS.4.rename}" verbose="true"/> --> + dest="downloads/${DIS.4.rename}" verbose="true"/> --> <echo message="${warningMessage}IEEE1278.4 retrieval to this location, use your browser to save ${ieeeBaseLinkUrl}${DIS.4.document}" file="${DIS.4.rename}"/> + <echo/> </target> <target name="download.IeeeDisStandards.retrieve"> @@ -129,40 +154,40 @@ <echo message="IEEE Explore: ${ieeeExploreUrl}"/> <!-- ======================== --> - <property name="DIS.1.document" value="6387564"/> - <property name="DIS.1.rename" value="IEEE1278.1-2012.DistributedInteractiveSimulation.ApplicationProtocols.${DIS.1.document}.pdf"/> - <echo message="see ${ieeeBasePageUrl}${DIS.1.document}"/> + <echo message="${DIS.1.title}"/> + <echo message="see ${ieeeBasePageUrl}${DIS.1.document}"/> <echo message="get ${ieeeBaseLinkUrl}${DIS.1.document}"/> + <echo message="to downloads/ subdirectory"/> <echo message="as ${DIS.1.rename}"/> <get src="${ieeeBaseLinkUrl}${DIS.1.document}" - dest="${DIS.1.rename}" verbose="true"/> + dest="downloads/${DIS.1.rename}" verbose="true"/> <!-- ======================== --> - <property name="DIS.2.document" value="7459689"/> - <property name="DIS.2.rename" value="IEEE1278.2-2015.DistributedInteractiveSimulation.CommunicationsServices.${DIS.2.document}.pdf"/> - <echo message="see ${ieeeBasePageUrl}${DIS.2.document}"/> + <echo message="${DIS.2.title}"/> + <echo message="see ${ieeeBasePageUrl}${DIS.2.document}"/> <echo message="get ${ieeeBaseLinkUrl}${DIS.2.document}"/> + <echo message="to downloads/ subdirectory"/> <echo message="as ${DIS.2.rename}"/> <get src="${ieeeBaseLinkUrl}${DIS.2.document}" - dest="${DIS.2.rename}" verbose="true"/> + dest="downloads/${DIS.2.rename}" verbose="true"/> <!-- ======================== --> - <property name="DIS.3.document" value="587529"/> - <property name="DIS.3.rename" value="IEEE1278.3-2015.DistributedInteractiveSimulation.CommunicationsServices.${DIS.3.document}.pdf"/> - <echo message="see ${ieeeBasePageUrl}${DIS.3.document}"/> + <echo message="${DIS.3.title}"/> + <echo message="see ${ieeeBasePageUrl}${DIS.3.document}"/> <echo message="get ${ieeeBaseLinkUrl}${DIS.3.document}"/> + <echo message="to downloads/ subdirectory"/> <echo message="as ${DIS.3.rename}"/> <get src="${ieeeBaseLinkUrl}${DIS.3.document}" - dest="${DIS.3.rename}" verbose="true"/> + dest="downloads/${DIS.3.rename}" verbose="true"/> <!-- ======================== --> - <property name="DIS.4.document" value="8685803"/> - <property name="DIS.4.rename" value="IEEE1278.4-2013.DistributedInteractiveSimulation.VV+A.${DIS.4.document}.pdf"/> - <echo message="see ${ieeeBasePageUrl}${DIS.4.document}"/> + <echo message="${DIS.4.title}"/> + <echo message="see ${ieeeBasePageUrl}${DIS.4.document}"/> <echo message="get ${ieeeBaseLinkUrl}${DIS.4.document}"/> + <echo message="to downloads/ subdirectory"/> <echo message="as ${DIS.4.rename}"/> <get src="${ieeeBaseLinkUrl}${DIS.4.document}" - dest="${DIS.4.rename}" verbose="true"/> + dest="downloads/${DIS.4.rename}" verbose="true"/> </target> <!-- =============================================== --> diff --git a/specifications/downloads/README.md b/specifications/downloads/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e32e010ddf99239ccf332b3b4706f60baf9fd619 --- /dev/null +++ b/specifications/downloads/README.md @@ -0,0 +1 @@ +This is a convenient directory for saving downloaded specification documents.