Skip to content
Snippets Groups Projects
Commit e1ba24eb authored by leahhedgcorth's avatar leahhedgcorth
Browse files

Submission of Assignment 1

parent 65cfec8b
No related branches found
No related tags found
No related merge requests found
...@@ -71,7 +71,7 @@ public class Assignment1Client ...@@ -71,7 +71,7 @@ public class Assignment1Client
System.out.println("=================================================="); System.out.println("==================================================");
System.out.print ("Client loop " + clientLoopCount + ": "); System.out.print ("Client loop " + clientLoopCount + ": ");
System.out.println("we are live!"); System.out.println("we are live for 20...!");
System.out.println("The message the server sent was: '" + serverMessage + "'"); System.out.println("The message the server sent was: '" + serverMessage + "'");
// socket gets closed, either automatically/silently by this code (or possibly by the server) // socket gets closed, either automatically/silently by this code (or possibly by the server)
......
...@@ -55,21 +55,21 @@ public class Assignment1Server { ...@@ -55,21 +55,21 @@ public class Assignment1Server {
PrintStream ps; PrintStream ps;
InetAddress localAddress, remoteAddress; InetAddress localAddress, remoteAddress;
int localPort, remotePort; int localPort, remotePort;
int serverLoopCount = 0; int serverLoopCount = 20;
// Server is up and waiting (i.e. "blocked" or paused) // Server is up and waiting (i.e. "blocked" or paused)
// Loop, infinitely, waiting for client connections. // Loop, infinitely, waiting for client connections.
// Stop the program somewhere else. // Stop the program somewhere else.
while (serverLoopCount < 20) { while (serverLoopCount > 0) {
// block until connected to a client // block until connected to a client
try ( Socket clientConnectionSocket = serverSocket.accept()) { try ( Socket clientConnectionSocket = serverSocket.accept()) {
serverLoopCount++; // increment at beginning of loop for reliability serverLoopCount--; // increment at beginning of loop for reliability
// Now hook everything up (i.e. set up the streams), Java style: // Now hook everything up (i.e. set up the streams), Java style:
os = clientConnectionSocket.getOutputStream(); os = clientConnectionSocket.getOutputStream();
ps = new PrintStream(os); ps = new PrintStream(os);
ps.println("This is response " + serverLoopCount + " produced by the server."); // this gets sent back to client! ps.println("Connection will end in: " + serverLoopCount + "..."); // this gets sent back to client!
// Print some information locally about the Socket connection. // Print some information locally about the Socket connection.
// This includes the port and IP numbers on both sides (the socket pair). // This includes the port and IP numbers on both sides (the socket pair).
...@@ -78,7 +78,7 @@ public class Assignment1Server { ...@@ -78,7 +78,7 @@ public class Assignment1Server {
localPort = clientConnectionSocket.getLocalPort(); localPort = clientConnectionSocket.getLocalPort();
remotePort = clientConnectionSocket.getPort(); remotePort = clientConnectionSocket.getPort();
System.out.print("Server loop " + serverLoopCount + ": "); //System.out.print("Server loop " + serverLoopCount + ": ");
// My socket pair connection looks like this, to localhost: // 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, 54876 ))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment