diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Pugh/Pugh3Client_homework2.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Pugh/Pugh3Client_homework2.java index 845d2559a782eb34054373eddf399f9359d48945..31734f0c3cbdfd0fc34a01c0c4a62ac41953bf82 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Pugh/Pugh3Client_homework2.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Pugh/Pugh3Client_homework2.java @@ -80,7 +80,7 @@ public class Pugh3Client_homework2 { System.out.println("That is a horrible joke."); } - if (clientLoopCount == 4){ + if (clientLoopCount >= 4){ System.out.println("No..."); } Thread.sleep(500l); // slow things down, for example 500l (long) = 500 msec diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Pugh/Pugh3Server.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Pugh/Pugh3Server.java index 38efa13d626cb33a4bc9ee3b050a1c70a060f48a..c136921f2499a80b273e4864ff7532995e882a45 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Pugh/Pugh3Server.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Pugh/Pugh3Server.java @@ -58,21 +58,8 @@ public class Pugh3Server { // 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."); // this gets sent back to client! + ps.println("This is response " + serverLoopCount + " produced by the server.\n"); // this gets sent back to client! - if (serverLoopCount == 1) { - System.out.println("Ready for some great Dad Jokes?!?"); - } - if (serverLoopCount == 2) { - System.out.println("Ok, get ready..."); - } - if (serverLoopCount == 3) { - System.out.print("A ham sandwich walks into a bar and orders a beer. The bartender says, “Sorry, we don’t serve food here.â€"); - } - - if (serverLoopCount == 4) { - System.out.println("Funny, right?"); - } // Print some information locally about the Socket connection. // This includes the port and IP numbers on both sides (the socket pair). localAddress = clientConnectionSocket.getLocalAddress(); @@ -80,7 +67,7 @@ public class Pugh3Server { localPort = clientConnectionSocket.getLocalPort(); remotePort = clientConnectionSocket.getPort(); - System.out.print("Server loop " + serverLoopCount + ": "); + System.out.print("Server loop: " + serverLoopCount + "\n"); // 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 )) @@ -90,14 +77,32 @@ public class Pugh3Server { System.out.println(Pugh3Server.class.getName() + " socket pair showing host name, address, port:"); System.out.println(" (( " + localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( " - + remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))"); + + remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))\n"); if (localAddress.getHostName().equals(localAddress.getHostAddress()) || remoteAddress.getHostName().equals(remoteAddress.getHostAddress())) { - System.out.println(" note HostName matches address if host has no DNS name"); + System.out.println(" note HostName matches address if host has no DNS name\n"); } } + if (serverLoopCount == 1) { + System.out.println("Ready for some great Dad Jokes?!?\n"); + } + if (serverLoopCount == 2) { + System.out.println("Ok, get ready...\n"); + } + if (serverLoopCount == 3) { + System.out.print("A ham sandwich walks into a bar and orders a beer. The bartender says, Sorry, we don’t serve food here.\n"); + } + + if (serverLoopCount == 4) { + System.out.println("Funny, right?\n"); + } + + if (serverLoopCount >= 5) { + System.out.print("Keep laughing, it's funny!\n"); + } + // 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