diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssignment2Client.java b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssignment2Client.java index 9141adfb87ed486a06da6763111b68c08aa470b3..907b346e174bc0c8d410401c35aebaf95ab218ad 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssignment2Client.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssignment2Client.java @@ -15,7 +15,7 @@ import java.net.Socket; import java.util.Scanner; /** - * + * @author DonMcGregor * @author garrettloeffelman */ public class LoeffelmanAssignment2Client { @@ -27,8 +27,10 @@ public class LoeffelmanAssignment2Client { try { System.out.println("creating socket"); - //This program establishes allows a client and server + //This program allows a client and server //to send messages back and forth. + + //Tell the client user that the client is listening for a message System.out.println("Listening:"); while (true) { // We request an IP to connect to ("localhost") and @@ -36,25 +38,31 @@ public class LoeffelmanAssignment2Client { // a connection to that IP in the form of the Socket // object; the server uses a ServerSocket to wait for // connections. - Socket socket = new Socket(LOCALHOST, 2317); // locohost? + Socket socket = new Socket(LOCALHOST, 2317); // localhost? + // Read the single line written by the server. We'd // do things a bit differently if many lines to be read // from the server, instead of one only. InputStream is = socket.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); - + + //This takes the message sent by the server and + //displays it. String serverMessage = br.readLine(); System.out.println("Server: " + serverMessage); + //Create an output streatm to send messages OutputStream os = socket.getOutputStream(); PrintStream ps = new PrintStream(os); + //Use a scanner to take user input from the key + //board and when prompted send it to the server. Scanner keyboard = new Scanner(System.in); System.out.println("Send Message to Server:"); String message = keyboard.nextLine(); ps.println(message); - + ps.flush(); // socket gets closed, either automatically/silently this code (or possibly by server) } // end while(true) } diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssignment2Server.java b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssignment2Server.java index 49b465f6b91c4af71ad927a2f96e851146a42f8e..303060e1e005c4e5ebb8dadf8ff4e270dedc506b 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssignment2Server.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssignment2Server.java @@ -36,10 +36,14 @@ public class LoeffelmanAssignment2Server { // Stop the program somewhere else. while (true) { + //Establish a client connection by accepting + //a socket request. Socket clientConnection = serverSocket.accept(); // block until connected OutputStream os = clientConnection.getOutputStream(); PrintStream ps = new PrintStream(os); + //Take input from the keyboard and use a print + //stream to send it to the client. Scanner keyboard = new Scanner(System.in); System.out.println("Send message to client:"); String message = keyboard.nextLine(); @@ -63,6 +67,8 @@ public class LoeffelmanAssignment2Server { System.out.println("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " + remoteAddress.toString() + ", " + remotePort + " ))"); + //Take an input stream that takes the message + //from the client and displays it. InputStream is = clientConnection.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr);