diff --git a/projects/Assignments/homework1/HanleyHomework1ConsoleLogs.docx b/projects/Assignments/homework1/HanleyHomework1ConsoleLogs.docx new file mode 100644 index 0000000000000000000000000000000000000000..9d2b935e1477f1dcecd6d720dabc06b894c67237 Binary files /dev/null and b/projects/Assignments/homework1/HanleyHomework1ConsoleLogs.docx differ diff --git a/projects/Assignments/homework1/HanleyTcpClient.java b/projects/Assignments/homework1/HanleyTcpClient.java new file mode 100644 index 0000000000000000000000000000000000000000..f849b8dbb930de299ac1ef34172f7c32497f5800 --- /dev/null +++ b/projects/Assignments/homework1/HanleyTcpClient.java @@ -0,0 +1,62 @@ +/* + * 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 Homework1; + +import java.io.*; +import java.net.*; + +/** + * + * @author Brian + */ +public class HanleyTcpClient { + public static void main(String[] args) + { + try + { + System.out.println("creating socket"); + + // 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); + + // 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); + + String serverMessage = br.readLine(); + System.out.println("1 The message the server sent was " + serverMessage); + + // Outgoing Messages + OutputStream os = socket.getOutputStream(); + PrintStream ps = new PrintStream(os); + ps.println("bbb report: X, Y, X " + System.currentTimeMillis()); + + serverMessage = br.readLine(); + System.out.println("2 The message the server sent was " + serverMessage); + + //os = socket.getOutputStream(); + // ps = new PrintStream(os); + ps.println("Final message from client " + System.currentTimeMillis()); + serverMessage = br.readLine(); + System.out.println("3 The message the server sent was " + serverMessage); + + + } + catch(Exception e) + { + System.out.println(e); + System.out.println("Problem with client"); + } + + } +} diff --git a/projects/Assignments/homework1/HanleyTcpServer.java b/projects/Assignments/homework1/HanleyTcpServer.java new file mode 100644 index 0000000000000000000000000000000000000000..744d05a1128c58e6f7068d47aa788151c2356fd6 --- /dev/null +++ b/projects/Assignments/homework1/HanleyTcpServer.java @@ -0,0 +1,104 @@ +//package Homework1; + + +import java.io.*; +import java.net.*; + + + +/** + * + * @author Brian + */ +public class HanleyTcpServer { + +/** + * Very slightly more complex than example1. A complete copy of + * example 2. The only thing this does + * differently is introduce a loop into the response, so you don't + * have to restart the program after one response. Also, it prints + * out the socket pair the server sees. Run the program via telnet + * several times and compare the socket pairs. + * + * telnet localhost 2317 + * + * If you're sophisticated you can contact the instructor's computer + * while running this program. + * + * telnet <ipOfServersLaptop> 2317 + * + * And have him display the socket pairs he got. + * @author mcgredo + */ + 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); + Socket clientConnection = serverSocket.accept(); + + // Loop, infinitely, waiting for client connections. + // Stop the program somewhere else. + while(true) + { + //Socket clientConnection = serverSocket.accept(); + OutputStream os = clientConnection.getOutputStream(); + PrintStream ps = new PrintStream(os); + + ps.println("This was written by the server"); + + // 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 + " ))"); + + //Exchange of Data + InputStream is = clientConnection.getInputStream(); + InputStreamReader isr = new InputStreamReader(is); + BufferedReader br = new BufferedReader(isr); + + String clientMessage = br.readLine(); + + if (clientMessage.startsWith("loc")){ + System.out.println("Location Report \n"+ clientMessage); + } + else System.out.println("Incoming Message \n" + clientMessage); + ps.println("Message received"); + + // 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(); + } + } + catch(Exception e) + { + System.out.println("problem with networking"); + } + + } + +} + diff --git a/projects/Assignments/homework1/HanleyUmlDrawingHomework1.vsdx b/projects/Assignments/homework1/HanleyUmlDrawingHomework1.vsdx new file mode 100644 index 0000000000000000000000000000000000000000..5e1b7182e7a5b79f0e6274747f5af0fb2173f4ba Binary files /dev/null and b/projects/Assignments/homework1/HanleyUmlDrawingHomework1.vsdx differ