diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Fetterolf/wiresharkproof.csv b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Fetterolf/wiresharkproof.csv new file mode 100644 index 0000000000000000000000000000000000000000..f6e1dae61f5c6d7ac7e5b66aa02ae8a4ca12a66b --- /dev/null +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Fetterolf/wiresharkproof.csv @@ -0,0 +1,86 @@ +No.,Time,Source,Destination,Protocol,Length,Info +1,0,172.20.154.253,239.255.255.250,IGMPv2,46,Membership Report group 239.255.255.250 +2,4.494902,172.20.154.253,224.0.0.252,IGMPv2,46,Membership Report group 224.0.0.252 +3,8.494797,172.20.154.253,224.0.0.251,IGMPv2,46,Membership Report group 224.0.0.251 +4,13.99937,172.20.154.253,224.0.0.251,IGMPv2,46,Membership Report group 224.0.0.251 +5,15.994927,172.20.154.253,224.0.0.252,IGMPv2,46,Membership Report group 224.0.0.252 +6,25.531061,::1,::1,TCP,86,51554 > 2317 [SYN] Seq=0 Win=65535 Len=0 MSS=65475 WS=256 SACK_PERM=1 +7,25.531136,::1,::1,TCP,86,"2317 > 51554 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=65475 WS=256 SACK_PERM=1" +8,25.531175,::1,::1,TCP,74,51554 > 2317 [ACK] Seq=1 Ack=1 Win=2618880 Len=0 +9,25.532262,::1,::1,TCP,87,"2317 > 51554 [PSH, ACK] Seq=1 Ack=1 Win=2618880 Len=13" +10,25.532282,::1,::1,TCP,74,51554 > 2317 [ACK] Seq=1 Ack=14 Win=2618880 Len=0 +11,25.532322,::1,::1,TCP,76,"2317 > 51554 [PSH, ACK] Seq=14 Ack=1 Win=2618880 Len=2" +12,25.532331,::1,::1,TCP,74,51554 > 2317 [ACK] Seq=1 Ack=16 Win=2618880 Len=0 +13,25.533723,::1,::1,TCP,86,51555 > 2317 [SYN] Seq=0 Win=65535 Len=0 MSS=65475 WS=256 SACK_PERM=1 +14,25.533789,::1,::1,TCP,74,"2317 > 51554 [FIN, ACK] Seq=16 Ack=1 Win=2618880 Len=0" +15,25.533794,::1,::1,TCP,86,"2317 > 51555 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=65475 WS=256 SACK_PERM=1" +16,25.533856,::1,::1,TCP,74,51554 > 2317 [ACK] Seq=1 Ack=17 Win=2618880 Len=0 +17,25.533863,::1,::1,TCP,74,51555 > 2317 [ACK] Seq=1 Ack=1 Win=327168 Len=0 +18,25.53414,::1,::1,TCP,88,"2317 > 51555 [PSH, ACK] Seq=1 Ack=1 Win=2618880 Len=14" +19,25.534158,::1,::1,TCP,74,51555 > 2317 [ACK] Seq=1 Ack=15 Win=327168 Len=0 +20,25.534184,::1,::1,TCP,76,"2317 > 51555 [PSH, ACK] Seq=15 Ack=1 Win=2618880 Len=2" +21,25.534194,::1,::1,TCP,74,51555 > 2317 [ACK] Seq=1 Ack=17 Win=327168 Len=0 +22,25.534318,::1,::1,TCP,74,"2317 > 51555 [FIN, ACK] Seq=17 Ack=1 Win=2618880 Len=0" +23,25.534336,::1,::1,TCP,74,51555 > 2317 [ACK] Seq=1 Ack=18 Win=327168 Len=0 +24,25.534912,::1,::1,TCP,86,51556 > 2317 [SYN] Seq=0 Win=65535 Len=0 MSS=65475 WS=256 SACK_PERM=1 +25,25.534994,::1,::1,TCP,86,"2317 > 51556 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=65475 WS=256 SACK_PERM=1" +26,25.535033,::1,::1,TCP,74,51556 > 2317 [ACK] Seq=1 Ack=1 Win=2618880 Len=0 +27,25.535278,::1,::1,TCP,93,"2317 > 51556 [PSH, ACK] Seq=1 Ack=1 Win=2618880 Len=19" +28,25.535304,::1,::1,TCP,74,51556 > 2317 [ACK] Seq=1 Ack=20 Win=2618880 Len=0 +29,25.535344,::1,::1,TCP,76,"2317 > 51556 [PSH, ACK] Seq=20 Ack=1 Win=2618880 Len=2" +30,25.535357,::1,::1,TCP,74,51556 > 2317 [ACK] Seq=1 Ack=22 Win=2618880 Len=0 +31,25.535502,::1,::1,TCP,74,"2317 > 51556 [FIN, ACK] Seq=22 Ack=1 Win=2618880 Len=0" +32,25.535517,::1,::1,TCP,74,51556 > 2317 [ACK] Seq=1 Ack=23 Win=2618880 Len=0 +33,25.536018,::1,::1,TCP,86,51557 > 2317 [SYN] Seq=0 Win=65535 Len=0 MSS=65475 WS=256 SACK_PERM=1 +34,25.53607,::1,::1,TCP,86,"2317 > 51557 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=65475 WS=256 SACK_PERM=1" +35,25.536106,::1,::1,TCP,74,51557 > 2317 [ACK] Seq=1 Ack=1 Win=327168 Len=0 +36,25.536311,::1,::1,TCP,81,"2317 > 51557 [PSH, ACK] Seq=1 Ack=1 Win=2618880 Len=7" +37,25.536333,::1,::1,TCP,74,51557 > 2317 [ACK] Seq=1 Ack=8 Win=327168 Len=0 +38,25.536374,::1,::1,TCP,76,"2317 > 51557 [PSH, ACK] Seq=8 Ack=1 Win=2618880 Len=2" +39,25.536389,::1,::1,TCP,74,51557 > 2317 [ACK] Seq=1 Ack=10 Win=327168 Len=0 +40,25.536546,::1,::1,TCP,74,"2317 > 51557 [FIN, ACK] Seq=10 Ack=1 Win=2618880 Len=0" +41,25.536563,::1,::1,TCP,74,51557 > 2317 [ACK] Seq=1 Ack=11 Win=327168 Len=0 +42,25.540671,::1,::1,TCP,74,"51557 > 2317 [RST, ACK] Seq=1 Ack=11 Win=0 Len=0" +43,25.540928,::1,::1,TCP,74,"51554 > 2317 [RST, ACK] Seq=1 Ack=17 Win=0 Len=0" +44,25.54098,::1,::1,TCP,74,"51555 > 2317 [RST, ACK] Seq=1 Ack=18 Win=0 Len=0" +45,25.541016,::1,::1,TCP,74,"51556 > 2317 [RST, ACK] Seq=1 Ack=23 Win=0 Len=0" +56,38.295834,::1,::1,TCP,86,51563 > 2317 [SYN] Seq=0 Win=65535 Len=0 MSS=65475 WS=256 SACK_PERM=1 +57,38.295874,::1,::1,TCP,86,"2317 > 51563 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=65475 WS=256 SACK_PERM=1" +58,38.29594,::1,::1,TCP,74,51563 > 2317 [ACK] Seq=1 Ack=1 Win=2618880 Len=0 +59,38.296716,::1,::1,TCP,87,"2317 > 51563 [PSH, ACK] Seq=1 Ack=1 Win=2618880 Len=13" +60,38.296732,::1,::1,TCP,74,51563 > 2317 [ACK] Seq=1 Ack=14 Win=2618880 Len=0 +61,38.296788,::1,::1,TCP,76,"2317 > 51563 [PSH, ACK] Seq=14 Ack=1 Win=2618880 Len=2" +62,38.296799,::1,::1,TCP,74,51563 > 2317 [ACK] Seq=1 Ack=16 Win=2618880 Len=0 +63,38.297568,::1,::1,TCP,86,51564 > 2317 [SYN] Seq=0 Win=65535 Len=0 MSS=65475 WS=256 SACK_PERM=1 +64,38.297623,::1,::1,TCP,86,"2317 > 51564 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=65475 WS=256 SACK_PERM=1" +65,38.297667,::1,::1,TCP,74,"2317 > 51563 [FIN, ACK] Seq=16 Ack=1 Win=2618880 Len=0" +66,38.297672,::1,::1,TCP,74,51564 > 2317 [ACK] Seq=1 Ack=1 Win=2618880 Len=0 +67,38.297712,::1,::1,TCP,74,51563 > 2317 [ACK] Seq=1 Ack=17 Win=2618880 Len=0 +68,38.297926,::1,::1,TCP,88,"2317 > 51564 [PSH, ACK] Seq=1 Ack=1 Win=2618880 Len=14" +69,38.297942,::1,::1,TCP,74,51564 > 2317 [ACK] Seq=1 Ack=15 Win=2618880 Len=0 +70,38.297967,::1,::1,TCP,76,"2317 > 51564 [PSH, ACK] Seq=15 Ack=1 Win=2618880 Len=2" +71,38.297976,::1,::1,TCP,74,51564 > 2317 [ACK] Seq=1 Ack=17 Win=2618880 Len=0 +72,38.298085,::1,::1,TCP,74,"2317 > 51564 [FIN, ACK] Seq=17 Ack=1 Win=2618880 Len=0" +73,38.2981,::1,::1,TCP,74,51564 > 2317 [ACK] Seq=1 Ack=18 Win=2618880 Len=0 +74,38.298642,::1,::1,TCP,86,51565 > 2317 [SYN] Seq=0 Win=65535 Len=0 MSS=65475 WS=256 SACK_PERM=1 +75,38.298697,::1,::1,TCP,86,"2317 > 51565 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=65475 WS=256 SACK_PERM=1" +76,38.298719,::1,::1,TCP,74,51565 > 2317 [ACK] Seq=1 Ack=1 Win=327168 Len=0 +77,38.29896,::1,::1,TCP,93,"2317 > 51565 [PSH, ACK] Seq=1 Ack=1 Win=2618880 Len=19" +78,38.298978,::1,::1,TCP,74,51565 > 2317 [ACK] Seq=1 Ack=20 Win=327168 Len=0 +79,38.299006,::1,::1,TCP,76,"2317 > 51565 [PSH, ACK] Seq=20 Ack=1 Win=2618880 Len=2" +80,38.299015,::1,::1,TCP,74,51565 > 2317 [ACK] Seq=1 Ack=22 Win=327168 Len=0 +81,38.299293,::1,::1,TCP,74,"2317 > 51565 [FIN, ACK] Seq=22 Ack=1 Win=2618880 Len=0" +82,38.299313,::1,::1,TCP,74,51565 > 2317 [ACK] Seq=1 Ack=23 Win=327168 Len=0 +83,38.299545,::1,::1,TCP,86,51566 > 2317 [SYN] Seq=0 Win=65535 Len=0 MSS=65475 WS=256 SACK_PERM=1 +84,38.299594,::1,::1,TCP,86,"2317 > 51566 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=65475 WS=256 SACK_PERM=1" +85,38.299633,::1,::1,TCP,74,51566 > 2317 [ACK] Seq=1 Ack=1 Win=2618880 Len=0 +86,38.299887,::1,::1,TCP,81,"2317 > 51566 [PSH, ACK] Seq=1 Ack=1 Win=2618880 Len=7" +87,38.29991,::1,::1,TCP,74,51566 > 2317 [ACK] Seq=1 Ack=8 Win=2618880 Len=0 +88,38.299946,::1,::1,TCP,76,"2317 > 51566 [PSH, ACK] Seq=8 Ack=1 Win=2618880 Len=2" +89,38.29996,::1,::1,TCP,74,51566 > 2317 [ACK] Seq=1 Ack=10 Win=2618880 Len=0 +90,38.300102,::1,::1,TCP,74,"2317 > 51566 [FIN, ACK] Seq=10 Ack=1 Win=2618880 Len=0" +91,38.300119,::1,::1,TCP,74,51566 > 2317 [ACK] Seq=1 Ack=11 Win=2618880 Len=0 +92,38.30487,::1,::1,TCP,74,"51563 > 2317 [RST, ACK] Seq=1 Ack=17 Win=0 Len=0" +93,38.304926,::1,::1,TCP,74,"51564 > 2317 [RST, ACK] Seq=1 Ack=18 Win=0 Len=0" +94,38.304957,::1,::1,TCP,74,"51565 > 2317 [RST, ACK] Seq=1 Ack=23 Win=0 Len=0" +95,38.304989,::1,::1,TCP,74,"51566 > 2317 [RST, ACK] Seq=1 Ack=11 Win=0 Len=0" diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCannClient.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannClient.java similarity index 94% rename from assignments/src/MV3500Cohort2019JulySeptember/homework2/McCannClient.java rename to assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannClient.java index f7d2c16c852479bd2b00ff703da586b19492f519..dad6563446742c8e1d3ca3f38c174c910eaa246f 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCannClient.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannClient.java @@ -3,8 +3,9 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package MV3500Cohort2019JulySeptember.homework2; +package MV3500Cohort2019JulySeptember.homework2.McCann; +import MV3500Cohort2019JulySeptember.homework2.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannHW2UML.pptx b/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannHW2UML.pptx new file mode 100644 index 0000000000000000000000000000000000000000..e54cf98d31a0847a548e01c28aa4cbc390c2148e Binary files /dev/null and b/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannHW2UML.pptx differ diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann Output.PNG b/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannOutput.PNG similarity index 100% rename from assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann Output.PNG rename to assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannOutput.PNG diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCannServer.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannServer.java similarity index 91% rename from assignments/src/MV3500Cohort2019JulySeptember/homework2/McCannServer.java rename to assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannServer.java index a2e06119396cb305302b527b8efae31e88007eac..208095fa2edf1790d004ba90acd62e1917ed75b3 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCannServer.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannServer.java @@ -3,8 +3,9 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package MV3500Cohort2019JulySeptember.homework2; +package MV3500Cohort2019JulySeptember.homework2.McCann; +import MV3500Cohort2019JulySeptember.homework2.*; import java.io.*; import java.net.*; import java.util.Scanner; @@ -35,13 +36,14 @@ public class McCannServer { while (true) { // block until connected to a client - try (Socket clientConnection = serverSocket.accept()) { + try (Socket clientConnection = serverSocket.accept()) { // Now hook everything up (i.e. set up the streams), Java style: os = clientConnection.getOutputStream(); ps = new PrintStream(os); Scanner keyboard = new Scanner(System.in); ps.println("What is your name?"); // this gets sent back to client! + //tried to add an input but couldn't get it to work //String message = keyboard.nextLine(); // ps.println(message); diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann_ServerOutput.PNG b/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannServerOutput.PNG similarity index 100% rename from assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann_ServerOutput.PNG rename to assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannServerOutput.PNG diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann_WireShark_output.PNG b/assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannWireSharkOutput.PNG similarity index 100% rename from assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann_WireShark_output.PNG rename to assignments/src/MV3500Cohort2019JulySeptember/homework2/McCann/McCannWireSharkOutput.PNG diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttClient.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttClient.java index 21af2d3830d6cd04bd1e255477f5034d414fae3a..4d39e6900fc4e61727c8a701ba777cecea5bd2a1 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttClient.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttClient.java @@ -4,19 +4,15 @@ 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. + * This is a client program that establishes a socket connection to a dispatch + * server, then it sends a simple math equation to be solved. * - * 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 Schutt */ public class SchuttClient { // 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"; + public static void main(String[] args) { @@ -28,17 +24,24 @@ public class SchuttClient { OutputStream os; PrintStream ps; String serverMessage; + String[] equations = new String[4]; + + equations[0] = "1 + 1"; + equations[1] = "2 + 2"; + equations[2] = "2 * 2"; + equations[3] = "3 * 3"; + int index = 1; try { - while (true) { - System.out.println("SchuttClient creating socket..."); + for(String eq : equations) { + System.out.println("SchuttClient creating socket #" + index + "..."); // 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? + socket = new Socket("localhost", 2317); // locohost? // Now hook everything up (i.e. set up the streams), Java style: // ** Added an output stream to the client so it can send a message to the server @@ -55,9 +58,13 @@ public class SchuttClient { System.out.println("=================================================="); System.out.println("Now we're talking!"); System.out.println("The message the server sent was: '" + serverMessage + "'"); - ps.println("Who's there?"); // Sends a message to the server // socket gets closed, either automatically/silently by this code (or possibly by the server) + ps.println(eq); + serverMessage = br.readLine(); + System.out.println(serverMessage); + System.out.println("==================================================="); + index++; } // end while(true) } catch (IOException e) { System.err.println("Problem with SchuttServerClient networking:"); // describe what is happening @@ -70,7 +77,7 @@ public class SchuttClient { } finally { // program exit: tell somebody about that - System.out.println("\nclient exit"); + } } } diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttClient.png b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttClient.png deleted file mode 100644 index dfe10a33e9c5396116732731ab6da92b702599e4..0000000000000000000000000000000000000000 Binary files a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttClient.png and /dev/null differ diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttServer.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttServer.java deleted file mode 100644 index e33440c56424fc1dc9acc5ec46431de09ae8cfb7..0000000000000000000000000000000000000000 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttServer.java +++ /dev/null @@ -1,99 +0,0 @@ -package MV3500Cohort2019JulySeptember.homework2.Schutt; - -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 SchuttServer { - - 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("SchuttServer has started..."); // it helps debugging to put this on console first - - ServerSocket serverSocket = new ServerSocket(2317); - OutputStream os; - PrintStream ps; - InputStream is; - InputStreamReader isr; - BufferedReader br; - String clientResponse; - InetAddress localAddress, remoteAddress; - int localPort, remotePort; - - // 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 clientConnection = serverSocket.accept()) { - - // Now hook everything up (i.e. set up the streams), Java style: - // Added an input stream to gather the message sent from the client - os = clientConnection.getOutputStream(); - is = clientConnection.getInputStream(); - isr = new InputStreamReader(is); - br = new BufferedReader(isr); - ps = new PrintStream(os); - - ps.println("Knock Knock!"); // this gets sent back to client! - - // Assigns the client message to a string - clientResponse = br.readLine(); - // Print some information locally about the Socket connection. - // This includes the port and IP numbers on both sides (the socket pair). - localAddress = clientConnection.getLocalAddress(); - remoteAddress = clientConnection.getInetAddress(); - localPort = clientConnection.getLocalPort(); - remotePort = clientConnection.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("SchuttServer socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " - + remoteAddress.toString() + ", " + remotePort + " ))"); - // Prints the message sent from the client - System.out.println("++++++++++++++++++++++++++++++++++++"); - System.out.println("Client Response: " + clientResponse); - System.out.println("===================================="); - - // 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 SchuttServer 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/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttServer.png b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttServer.png deleted file mode 100644 index 62aebd4d816b55a514a037bff36c384b65f5f833..0000000000000000000000000000000000000000 Binary files a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttServer.png and /dev/null differ diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttServerDispatcher.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttServerDispatcher.java new file mode 100644 index 0000000000000000000000000000000000000000..1808be2820dacdde1592fd481bc9a07d1581ee3a --- /dev/null +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttServerDispatcher.java @@ -0,0 +1,56 @@ +package MV3500Cohort2019JulySeptember.homework2.Schutt; + +import java.io.IOException; +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 Schutt + */ +public class SchuttServerDispatcher { + + public static void main(String[] args) // execution starts here + { + try{ + ServerSocket serverSocket = new ServerSocket(2317); + int connectionCount = 0; + + System.out.println("SchuttServerDispatcher ready to accept socket connections..."); + + while(true){ + Socket clientConnection = serverSocket.accept(); + connectionCount++; + System.out.println("========================================================"); + System.out.println("SchuttServerDispatcher.handlerThread invocation for connection #" + connectionCount + "..."); + SchuttThreadHandler handlerThread = new SchuttThreadHandler(clientConnection); + handlerThread.start(); + System.out.println("SchuttServerDispatcher.handlerThread is launched, awaiting next connection..."); + } + + } catch (IOException e){ + System.out.println("Problem with SchuttServerDispatcher networking:"); + System.out.println("Error: " + e); + if(e instanceof java.net.BindException){ + System.out.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + + System.out.println("============================================================="); + } + +} + diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttThreadHandler.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttThreadHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..651402c406da2c747f2054fd76f7d5fa8d7c5766 --- /dev/null +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttThreadHandler.java @@ -0,0 +1,86 @@ +package MV3500Cohort2019JulySeptember.homework2.Schutt; + +import java.io.*; +import java.net.*; + +/** + * A program that handles all logic associated with one socket connection by + * running in a thread of its own. This is the server portion as well, so we + * artificially invent what happens if the server can't respond to a connection + * for several seconds. Warning: do not run this class! It is created + * automatically by TcpExample4DispatchServer. + * + * @author Schutt + */ +public class SchuttThreadHandler extends Thread { + + /** + * The socket connection to a client + */ + Socket socket; + int num1; + int num2; + int output; + + /** + * The thread constructor creates the socket from a ServerSocket, and passes + * one to the thread responsible for handling the connection. + * + * @param socket The socket connection handled by this thread + */ + public SchuttThreadHandler(Socket socket) { + this.socket = socket; + } + + /** + * Handles one connection. We add an artificial slowness to handling the + * connection with a sleep(). This means the client won't see a server + * connection response for ten seconds (default). + */ + // @overriding run() method in Java Thread class is deliberate + @Override + public void run() { + try { + System.out.println("SchuttThreadHandler starting to handle a thread..."); + // get the connection output stream, then wait a period of time. + OutputStream os = socket.getOutputStream(); + PrintStream ps = new PrintStream(os); + InputStream is = socket.getInputStream(); + InputStreamReader isr = new InputStreamReader(is); + BufferedReader br = new BufferedReader(isr); + + ps.println("Please send your equation!"); + + String clientInput = br.readLine(); + System.out.println("The Client's equation is: " + clientInput); + if(clientInput.contains("+")){ + + num1 = (int)clientInput.charAt(0); + num2 = (int)clientInput.charAt(4); + System.out.println(num1 + " " + num2); + + output = num1 + num2; + } + + if(clientInput.contains("*")){ + num1 = (int)clientInput.charAt(0); + num2 = (int)clientInput.charAt(4); + + output = num1 * num2; + } + System.out.println("The Client's answer is: " + output); + ps.println("The answer to your equation is: " + output); + ps.flush(); + socket.close(); + + } catch (IOException e) // either a networking or a threading problem + { + System.out.println("Problem with TcpExample4HandlerThread 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 + if (e instanceof java.net.BindException) { + System.out.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + } +} diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttWireSharkClient.png b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttWireSharkClient.png deleted file mode 100644 index e9c9ad5003f66fe714161791fb7b7f47dc59d724..0000000000000000000000000000000000000000 Binary files a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttWireSharkClient.png and /dev/null differ diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttWireSharkServer.png b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttWireSharkServer.png deleted file mode 100644 index 1dd65a3c63f4974963bd7f49f0acd9a311a37764..0000000000000000000000000000000000000000 Binary files a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttWireSharkServer.png and /dev/null differ