diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/homework1/SeversonAssignment1.java b/deliverables/src/MV3500Cohort2018JulySeptember/homework1/SeversonAssignment1.java index 772d7420612356339881871a0cef9aa155e3490b..59d43bdd8859f695c3bb9361a7933fe594705744 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/homework1/SeversonAssignment1.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/homework1/SeversonAssignment1.java @@ -25,22 +25,30 @@ public class SeversonAssignment1 { try { + //Instantiate socket and wait for connection ServerSocket serverSocket = new ServerSocket(2317); + //Count the number of connections int connection = 0; + //Loop until client connection is made while (true) { + //Socket making connection with the client Socket clientConnection = serverSocket.accept(); + //number of connections is incremented by one when the connection occurs connection++; + //write output text to the client and server OutputStream os = clientConnection.getOutputStream(); PrintStream ps = new PrintStream(os); + //connection responses to the server and client ps.println("This client response was written by server"); // to remote client System.out.println("This server response was written by server"); // to server console ps.println("Got another connection! " + "--Number " + connection); + //Print port and IP addresses of the server connection InetAddress localAddress = clientConnection.getLocalAddress(); InetAddress remoteAddress = clientConnection.getInetAddress(); @@ -49,6 +57,7 @@ public class SeversonAssignment1 { System.out.println("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " + remoteAddress.toString() + ", " + remotePort + " ))"); + //close the connection and inform the client of the close ps.println("The client connection is closed ---- BYE!"); ps.flush(); clientConnection.close();