diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoClient.java b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoClient.java new file mode 100644 index 0000000000000000000000000000000000000000..2d876c8b629df797e98072e3692674753b033780 --- /dev/null +++ b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoClient.java @@ -0,0 +1,77 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package MV3500Cohort2018JulySeptember.homework2.Demchko; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintStream; +import java.net.Socket; +import java.util.Scanner; + +/** + * + * @author garrettloeffelman + */ +public class DemchkoClient { + + public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; // String constant, i.e. 127.0.0.1 + + public static void main(String[] args) { + + try { + System.out.println("Answer this question:"); + + //This program establishes allows a client and server + //to send messages back and forth. + System.out.println("Why did the chicken cross the road?"); + while (true) { + // We request an IP to connect to ("localhost") and + // port number at that IP (2317). This establishes + // 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); // this is the local host for the socket + // 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. + OutputStream os = socket.getOutputStream(); + OutputStreamWriter osw = new OutputStreamWriter(os); + BufferedWriter bw = new BufferedWriter(osw); + + InputStream is = socket.getInputStream(); + InputStreamReader isr = new InputStreamReader(is); + BufferedReader br = new BufferedReader(isr); + + String inputMessage = "To get to the other side"; + //System.out.println("Joe says: Who's there? "); + String sendMessage = inputMessage + "\n"; + bw.write(sendMessage); + bw.flush(); + String input = br.readLine(); + System.out.println(input + "\n" + input + " no."); + + // String serverMessage = br.readLine(); + System.out.println("Try again." ); // + serverMessage + + String update = br.readLine(); + // String sendUpdate = update + "\n"; + System.out.println("The correct answer is to get to the other side"); + + } // end while(true) + } catch (IOException e) { + System.out.println("Problem with client: "); // describe what is happening + System.out.println(e); + } + // program exit + System.out.println("client exit"); + } + +} diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoHW2UML.pptx b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoHW2UML.pptx new file mode 100644 index 0000000000000000000000000000000000000000..7ff1109d06974fefd3f761adda958d0b280b6a2c Binary files /dev/null and b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoHW2UML.pptx differ diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoOutput1.png b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoOutput1.png new file mode 100644 index 0000000000000000000000000000000000000000..e079923ffe4b1d907d076e5a5eb65a7f5d2c1fe0 Binary files /dev/null and b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoOutput1.png differ diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoOutput2.png b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoOutput2.png new file mode 100644 index 0000000000000000000000000000000000000000..7e702d7acdbf009ee216a120537b524f092a7f41 Binary files /dev/null and b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoOutput2.png differ diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoServer.java b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoServer.java new file mode 100644 index 0000000000000000000000000000000000000000..5f4299149deebc775f8b77134817150ac30a0627 --- /dev/null +++ b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoServer.java @@ -0,0 +1,82 @@ +package MV3500Cohort2018JulySeptember.homework2.Demchko; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.PrintStream; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.Scanner; + +/** + * + * @author garrettloeffelman + */ +public class DemchkoServer { + + @SuppressWarnings("ConvertToTryWithResources") + 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. + + ServerSocket serverSocket = new ServerSocket(2317); + + // Loop, infinitely, waiting for client connections. + // Stop the program somewhere else. + while (true) + { + Socket clientConnection = serverSocket.accept(); // block until connected + OutputStream os = clientConnection.getOutputStream(); + PrintStream ps = new PrintStream(os); + + Scanner keyboard = new Scanner(System.in); + System.out.println("Why did the chicken cross the road?"); + String message = keyboard.nextLine(); + ps.println(message); + + // Print some information locally about the Socket + // connection. This includes the port and IP numbers + // on both sides (the socket pair.) + InetAddress localAddress = clientConnection.getLocalAddress(); + InetAddress remoteAddress = clientConnection.getInetAddress(); + + int localPort = clientConnection.getLocalPort(); + int remotePort = clientConnection.getPort(); + + // 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("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " + + remoteAddress.toString() + ", " + remotePort + " ))"); + + InputStream is = clientConnection.getInputStream(); + InputStreamReader isr = new InputStreamReader(is); + BufferedReader br = new BufferedReader(isr); + + String serverMessage = br.readLine(); + System.out.println("This time try " + serverMessage); + + + // Notice the use of flush() and close(). Without + // the close() to Socket object may stay open for + // a while after the client has stopped needing this + // connection. Close() explicitly ends the connection. + ps.flush(); + clientConnection.close(); // like it or not, you're outta here! + } + } + catch (IOException e) { + System.out.println("There is a problem with networking" + e); + } + } + +} diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Furr/FurrTcpClient.java b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Furr/FurrTcpClient.java index 31cba45f8da9a170365599c6b36ffdb0c3e5349b..3dcd83e8e577ad6e9d7eb10257948eab7fc32725 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Furr/FurrTcpClient.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Furr/FurrTcpClient.java @@ -42,7 +42,7 @@ public class FurrTcpClient { int x = 0; //for testing I have a iterator to close connection, if I get netbeans //up and running will try with the open connection condition. - while (x < 10)//openConnection) + while (openConnection) //x<10 will also work. { System.out.println("\nType something to the server: "); Scanner in = new Scanner(System.in); // gets input from console/output window diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Furr/FurrTcpServer.java b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Furr/FurrTcpServer.java index 0e3ed9bcb07fbd335a87f53cd6589cd764077fa7..255ab03e5e2b8a6941a327131e858502fc55b3ae 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Furr/FurrTcpServer.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Furr/FurrTcpServer.java @@ -85,10 +85,10 @@ public class FurrTcpServer { { //need check to see if - System.out.println("\n" + line); - ps.println("\tThe SERVER has responded with: " + responses[index]); - System.out.println("Server has sent: " + responses[index]); - index++; + System.out.println("\n" + line); //prints out what is recieved from client + ps.println("\tThe SERVER has responded with: " + responses[index]); //sends the prewritten response + System.out.println("Server has sent: " + responses[index]); //tells server user what was sent + index++; //goes to next response. // Notice the use of flush() and close(). Without // the close() to Socket object may stay open for diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Furr/Furr_Homework_2_Screenshots.pptx b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Furr/Furr_Homework_2_Screenshots.pptx new file mode 100644 index 0000000000000000000000000000000000000000..bad267752bc02f53e66e16a98a061641048042d7 Binary files /dev/null and b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Furr/Furr_Homework_2_Screenshots.pptx differ diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssigment2ScreenShots.pptx b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssigment2ScreenShots.pptx new file mode 100644 index 0000000000000000000000000000000000000000..0f0a8e048387c3c4cccc16c2ba6df3f63ee34b19 Binary files /dev/null and b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssigment2ScreenShots.pptx differ 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); diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssignment2_UML.pptx b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssignment2_UML.pptx new file mode 100644 index 0000000000000000000000000000000000000000..b437fbf3d4aec60553fe2631042aab8690e38efe Binary files /dev/null and b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Loeffelman/LoeffelmanAssignment2_UML.pptx differ