From 2eff95fa909db76232a3ed1b1233d9a91459d457 Mon Sep 17 00:00:00 2001 From: Sean Islas <seanislas@whiteoakfarmandranch.com> Date: Tue, 18 Apr 2023 20:29:37 -0700 Subject: [PATCH] Submission for Assignment1 --- .../homework1/Islas/HW1Client.java | 29 ++++++++++--- .../homework1/Islas/HW1Server.java | 43 ++++++++++++++----- 2 files changed, 56 insertions(+), 16 deletions(-) diff --git a/assignments/src/MV3500Cohort2023MarchJune/homework1/Islas/HW1Client.java b/assignments/src/MV3500Cohort2023MarchJune/homework1/Islas/HW1Client.java index 8453ebfd48..6f01a415ef 100644 --- a/assignments/src/MV3500Cohort2023MarchJune/homework1/Islas/HW1Client.java +++ b/assignments/src/MV3500Cohort2023MarchJune/homework1/Islas/HW1Client.java @@ -45,7 +45,7 @@ public class HW1Client { while (true) { clientLoopCount++; // increment at beginning of loop for reliability - System.out.println(HW1Client.class.getName() + " creating socket..."); + // System.out.println(HW1Client.class.getName() + " creating socket..."); // We request an IP to connect to ("localhost") and // port number at that IP (2317). This establishes @@ -63,11 +63,28 @@ public class HW1Client { // 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 talking!"); - System.out.println("The message the server sent was: '" + serverMessage + "'"); + // System.out.println("=================================================="); + + // First pose + if (clientLoopCount % 2 == 0) { + System.out.println(" O/ "); // head + System.out.println(" /| "); // arms + System.out.println(" /_\\ "); // legs + System.out.println(" | | "); // torso + System.out.println(); + } + + // Second pose + else { + System.out.println(" \\O "); // head + System.out.println(" |\\ "); // arms + System.out.println(" /_\\ "); // legs + System.out.println(" | | "); // torso + System.out.println(); + } + // System.out.print ("Client loop " + clientLoopCount + ": "); + // System.out.println("now we're talking!"); + // 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) diff --git a/assignments/src/MV3500Cohort2023MarchJune/homework1/Islas/HW1Server.java b/assignments/src/MV3500Cohort2023MarchJune/homework1/Islas/HW1Server.java index eb22ab48eb..d9619b9c7a 100644 --- a/assignments/src/MV3500Cohort2023MarchJune/homework1/Islas/HW1Server.java +++ b/assignments/src/MV3500Cohort2023MarchJune/homework1/Islas/HW1Server.java @@ -36,14 +36,15 @@ public class HW1Server { * 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(HW1Server.class.getName() + " has started..."); // it helps debugging to put this on console first - + // System.out.println(HW1Server.class.getName() + " has started..."); // it helps debugging to put this on console first + System.out.println("May I have this dance?"); ServerSocket serverSocket = new ServerSocket(2317); OutputStream os; PrintStream ps; @@ -51,11 +52,11 @@ public class HW1Server { int localPort, remotePort; int serverLoopCount = 0; + boolean keepGoing = true; // Server is up and waiting (i.e. "blocked" or paused) // Loop, infinitely, waiting for client connections. // Stop the program somewhere else. - while (true) { - + while (keepGoing) { // block until connected to a client try (Socket clientConnectionSocket = serverSocket.accept()) { @@ -72,18 +73,40 @@ public class HW1Server { remoteAddress = clientConnectionSocket.getInetAddress(); localPort = clientConnectionSocket.getLocalPort(); remotePort = clientConnectionSocket.getPort(); - - System.out.print ("Server loop " + serverLoopCount + ": "); + + if (serverLoopCount > 100) { + keepGoing = false; + } + // First pose + if (serverLoopCount % 2 == 0) { + System.out.println(" O/ "); // head + System.out.println(" /| "); // arms + System.out.println(" / \\ "); // legs + System.out.println(" | | "); // torso + System.out.println(); + } + + // Second pose + else { + System.out.println(" \\O "); // head + System.out.println(" |\\ "); // arms + System.out.println(" / \\ "); // legs + System.out.println(" | | "); // torso + System.out.println(); + } + + + // 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(HW1Server.class.getName() + " socket pair showing host name, address, port:"); - System.out.println(" (( " + - localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( " + - remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))"); + // System.out.println(HW1Server.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())) -- GitLab