diff --git a/.gitignore b/.gitignore index 6395878b5a6d7bce879d028d984d2a666dfba4b5..c1c7d264dcf05448302825caa3c190b08424c7b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,10 @@ # https://git-scm.com/docs/gitignore **/genfiles.properties -/nbproject/build-impl.xml~ -/nbproject/private/ +**/build-impl.xml +**/build-impl.xml~ +**/private/ + /assignments/build/ /assignments/dist/ /assignments/dist/javadoc/ @@ -11,8 +13,6 @@ /assignments/nbproject/private/ /assignments/pduLog/PduCaptureLog*.dislog /examples/pduLog/PduCaptureLog*.dislog -/examples/BasicServletDemo/nbproject/private/ -/examples/WebsocketGateway/nbproject/private/ /examples/manifest.mf /examples/build/ /examples/dist/ @@ -35,36 +35,31 @@ !/specifications/2019-SIW-Presentation-039_CompressedDis.pdf !/specifications/IeeeDisPduColorFigures.pdf /specifications/downloads/*.pdf -/examples/WebsocketGateway/build/ -/examples/WebsocketGateway/dist/ -/examples/BasicServletDemo/dist/ -/examples/BasicServletDemo/build/ -/examples/DisShooting/build/ -/examples/DisShooting/dist/ -/examples/DisShooting/nbproject/private/ -/examples/DisDemo/nbproject/private/ -/examples/DisDemo/build/ -/examples/DisDemo/dist/ -/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/nbproject/private/ -/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/build/ -/examples/nbproject/genfiles.properties -/examples/nbproject/build-impl.xml -assignments/src/MV3500Cohort2022MayJune/homework2/Royer/build/ +/archive/MV3302ClassCode/build/ +/archive/MV3302ClassCode/dist/ +/archive/MV3302ClassCode/nbproject/private/ + +/examples/otherProjects/BasicServletDemo/build/ +/examples/otherProjects/BasicServletDemo/dist/ +/examples/otherProjects/BasicServletDemo/nbproject/private/ + +/examples/otherProjects/DisDemo/build/ +/examples/otherProjects/DisDemo/dist/ +/examples/otherProjects/DisDemo/nbproject/private/ + +/examples/otherProjects/DisShooting/build/ +/examples/otherProjects/DisShooting/dist/ +/examples/otherProjects/DisShooting/nbproject/private/ + +/examples/otherProjects/WebsocketGateway/build/ +/examples/otherProjects/WebsocketGateway/dist/ +/examples/otherProjects/WebsocketGateway/nbproject/private/ + +# unable to fix, retained as .zip +/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/build/ +/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/build/ +/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/nbproject/private/ /assignments/src/MV3500Cohort2022MayJune/projects/Royer/TwoCranesBerth/nbproject/private/ /assignments/src/MV3500Cohort2022MayJune/projects/Royer/TwoCranesBerth/nbproject/build-impl.xml~ /assignments/src/MV3500Cohort2022MayJune/projects/Royer/TwoCranesBerth/pduLog/ -/examples/projects/BasicServletDemo/build/ -/examples/projects/BasicServletDemo/dist/ -/examples/projects/DisDemo/build/ -/examples/projects/BasicServletDemo/nbproject/private/ -/examples/projects/DisDemo/nbproject/private/ -/examples/projects/DisDemo/dist/ -/examples/projects/DisShooting/build/ -/examples/projects/DisShooting/nbproject/private/ -/examples/projects/WebsocketGateway/build/ -/examples/projects/WebsocketGateway/nbproject/private/ -/examples/otherProjects/DisShooting/nbproject/private/private.xml -/examples/otherProjects/DisShooting/build/ -genfiles.properties -/archive/MV3302ClassCode/nbproject/private/ diff --git a/assignments/nbproject/README.md b/assignments/nbproject/README.md index 3a9a00a86b26bd3c94208567dbc9fd73621f1465..6fe5f360d72e7b1e8f4f12a97de642bc8b0762da 100644 --- a/assignments/nbproject/README.md +++ b/assignments/nbproject/README.md @@ -1,2 +1,3 @@ The nbproject directory holds [Netbeans](https://netbeans.org) project information. -Students don't need to modify anything here. + +Students don't need to modify anything in this directory. diff --git a/assignments/nbproject/project.xml b/assignments/nbproject/project.xml index 16d948e42e3fe39705fc317350ee522a27f414e0..ec9c9401e07d97eb2d28c832cc9985585aeb9f06 100644 --- a/assignments/nbproject/project.xml +++ b/assignments/nbproject/project.xml @@ -15,6 +15,7 @@ <word>accessor</word> <word>autogeneration</word> <word>classpath</word> + <word>Cygwin</word> <word>deliverables</word> <word>docx</word> <word>https</word> diff --git a/assignments/src/MV3500Cohort2024JulySeptember/homework1/Lennon/README.md b/assignments/src/MV3500Cohort2024JulySeptember/homework1/Lennon/README.md index e5bd42a3887286271cc8c591aea01fa2b56f783c..13c2f323911fb6246bc4d758e33f0498b7c1f7e8 100644 --- a/assignments/src/MV3500Cohort2024JulySeptember/homework1/Lennon/README.md +++ b/assignments/src/MV3500Cohort2024JulySeptember/homework1/Lennon/README.md @@ -1,6 +1,5 @@ ## Homework 1: Unicast Networking -Welcome everybody! This is where your homework goes. Deliverables: @@ -9,3 +8,5 @@ Deliverables: Please see the [README.md](../../../README.md) in the parent [assignments](../../../../assignments) directory for detailed instructions. + +Code modified as instructed, and tested diff --git a/assignments/src/MV3500Cohort2024JulySeptember/homework1/Timberlake/Client.java b/assignments/src/MV3500Cohort2024JulySeptember/homework1/Timberlake/Client.java new file mode 100644 index 0000000000000000000000000000000000000000..d905f89d60ba8046d823ca966cca61692c9f8bd0 --- /dev/null +++ b/assignments/src/MV3500Cohort2024JulySeptember/homework1/Timberlake/Client.java @@ -0,0 +1,51 @@ +package MV3500Cohort2024JulySeptember.homework1.Timberlake; + +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; +import java.util.Scanner; + +/** + * + * @author Jack + */ +public class Client { + public static void main(String[] args) { + DatagramSocket socket = null; + Scanner scanner = new Scanner(System.in); + try { + // Create a socket to communicate with the server + socket = new DatagramSocket(); + InetAddress serverAddress = InetAddress.getByName("localhost"); // Server address (localhost for testing) + byte[] sendData = new byte[1024]; // Buffer to store data to send + byte[] receiveData = new byte[1024]; // Buffer to store received data + + // Get user input + System.out.print("Enter message to send to server: "); + String message = scanner.nextLine(); //Read user input + + // Send message to server + //String message = "Hello from client!"; // Message to send + sendData = message.getBytes(); // Convert message to bytes + DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, serverAddress, 9876); + socket.send(sendPacket); // Send packet to server + + // Receive response from server + DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); + socket.receive(receivePacket); // Blocking call until a packet is received + String responseMessage = new String(receivePacket.getData(), 0, receivePacket.getLength()); + System.out.println("Client received: " + responseMessage); // Print received response + + } catch (Exception e) { + e.printStackTrace(); // Print any exceptions that occur + + } finally { + if (scanner != null) { + scanner.close(); // Close scanner + } + if (socket != null && !socket.isClosed()) { + socket.close(); // Close the socket to release resources + } + } + } +} diff --git a/assignments/src/MV3500Cohort2024JulySeptember/homework1/Timberlake/Server.java b/assignments/src/MV3500Cohort2024JulySeptember/homework1/Timberlake/Server.java new file mode 100644 index 0000000000000000000000000000000000000000..54b88a994bcad4a4313adad0f55ce44cd0910a05 --- /dev/null +++ b/assignments/src/MV3500Cohort2024JulySeptember/homework1/Timberlake/Server.java @@ -0,0 +1,44 @@ +package MV3500Cohort2024JulySeptember.homework1.Timberlake; + +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; + +/** + * + * @author Jack + */ +public class Server { + public static void main(String[] args) { + DatagramSocket socket = null; + + try { + // Create a socket to listen on port 9876 + socket = new DatagramSocket(9876); + byte[] receiveData = new byte[1024]; // Buffer to store incoming data + byte[] sendData = new byte[1024]; // Buffer to store outgoing data + + while (true) { + // Receive packet from client + DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); + socket.receive(receivePacket); // Blocking call until a packet is received + String message = new String(receivePacket.getData(), 0, receivePacket.getLength()); + System.out.println("Server received: " + message); // Print received message + + // Prepare response to client + InetAddress clientAddress = receivePacket.getAddress(); // Get client's address + int clientPort = receivePacket.getPort(); // Get client's port + String responseMessage = "Hello From Server, I received: " + message; // Response message + sendData = responseMessage.getBytes(); // Convert response message to bytes + DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, clientAddress, clientPort); + socket.send(sendPacket); // Send response packet to client + } + } catch (Exception e) { + e.printStackTrace(); // Print any exceptions that occur + } finally { + if (socket != null && !socket.isClosed()) { + socket.close(); // Close the socket to release resources + } + } + } +} diff --git a/examples/nbproject/project.properties b/examples/nbproject/project.properties index 5553e93238a571074b0bd63d4a5b39c867f777d3..b0f27ba21430babba5e31e0c6d9018597a3f2089 100644 --- a/examples/nbproject/project.properties +++ b/examples/nbproject/project.properties @@ -65,8 +65,8 @@ javac.modulepath= javac.processormodulepath= javac.processorpath=\ ${javac.classpath} -javac.source=21 -javac.target=21 +javac.source=22 +javac.target=22 javac.test.classpath=\ ${javac.classpath}:\ ${build.classes.dir} diff --git a/examples/otherProjects/WebsocketGateway/nbproject/project.properties b/examples/otherProjects/WebsocketGateway/nbproject/project.properties index 34dbaad695fe0f314a275800022aab05e88a5563..ecad0e0a060e89989c67dcd1b4528a1e4c223181 100644 --- a/examples/otherProjects/WebsocketGateway/nbproject/project.properties +++ b/examples/otherProjects/WebsocketGateway/nbproject/project.properties @@ -39,7 +39,7 @@ file.reference.jetty-servlet.jar=lib/jetty-servlet-9.4.31.v20200723.jar file.reference.jetty-util.jar=lib/jetty-util-9.4.31.v20200723.jar file.reference.jetty-webapp.jar=lib/jetty-webapp-9.4.31.v20200723.jar file.reference.jetty-xml.jar=lib/jetty-xml-9.4.31.v20200723.jar -file.reference.opendis7-full.jar=../../lib/opendis7-full.jar +file.reference.opendis7-full.jar=../../../lib/opendis7-full.jar file.reference.servlet-api-3.1.jar=lib/servlet-api-3.1.jar file.reference.slf4j-api-1.7.5.jar=lib/slf4j-api-1.7.5.jar file.reference.slf4j-jdk14-1.7.30.jar=lib/slf4j-jdk14-1.7.30.jar diff --git a/examples/otherProjects/WebsocketGateway/src/edu/nps/moves/gateway/package-info.java b/examples/otherProjects/WebsocketGateway/src/edu/nps/moves/gateway/package-info.java index cdc37d0982e95603fd2f6194fc13d9bb7b1646ca..9ea7e0d87ec1a8053c73f858ae25b1edaf932921 100644 --- a/examples/otherProjects/WebsocketGateway/src/edu/nps/moves/gateway/package-info.java +++ b/examples/otherProjects/WebsocketGateway/src/edu/nps/moves/gateway/package-info.java @@ -2,11 +2,11 @@ * <p>WebSocket server and 3JS example, supporting the NPS MOVES MV3500 Networked Graphics course.</p> * * <p>Additional details are provided in the - * <a href="../../../../../otherProjects/WebsocketGateway/README.txt">README.txt</a> file.</p> + * <a href="../../../../../otherProjects/WebsocketGateway/README.txt" target="_blank">README.txt</a> file.</p> * * @see java.lang.Package - * @see <a href="https://stackoverflow.com/questions/22095487/why-is-package-info-java-useful">StackOverflow: why-is-package-info-java-useful</a> - * @see <a href="https://stackoverflow.com/questions/624422/how-do-i-document-packages-in-java">StackOverflow: how-do-i-document-packages-in-java</a> + * @see <a href="https://stackoverflow.com/questions/22095487/why-is-package-info-java-useful" target="_blank">StackOverflow: why-is-package-info-java-useful</a> + * @see <a href="https://stackoverflow.com/questions/624422/how-do-i-document-packages-in-java" target="_blank">StackOverflow: how-do-i-document-packages-in-java</a> */ package edu.nps.moves.gateway; diff --git a/examples/src/TcpExamples/TcpExample2ConnectionCounting.java b/examples/src/TcpExamples/TcpExample2ConnectionCounting.java index de9a434599c0f5bff320eab63a516922a837af3d..56226695ffacbe0ed0b3437978dc591c1dfb1771 100644 --- a/examples/src/TcpExamples/TcpExample2ConnectionCounting.java +++ b/examples/src/TcpExamples/TcpExample2ConnectionCounting.java @@ -63,7 +63,7 @@ public class TcpExample2ConnectionCounting try { // welcome aboard messages - System.out.println("TcpExample2ConnectionCounting has started and is waiting for a connection."); + System.out.println(TcpExample2ConnectionCounting.class.getName() + " has started and is waiting for a connection."); System.out.println(" help: https://savage.nps.edu/Savage/developers.html#telnet"); System.out.println(" Windows ipconfig (or Mac ifconfig) indicates current IPv4_Address (for example local wireless IP address)"); System.out.println(" Windows enter (telnet localhost 2317) or Mac enter (nc localhost 2317) for loopback operation, or" ); @@ -76,26 +76,33 @@ public class TcpExample2ConnectionCounting int connectionCount = 0; // state variable ServerSocket serverSocket = new ServerSocket(2317); // server decides here what port to listen on. - // of interest: often client doesn't care what port it uses locally when connecting to that server port. + // of interest: often client doesn't care what port it uses locally when connecting to that server port. + + OutputStream outputStream; // can declare these early, but... + PrintStream printStream; // note initial values are null, they still need to be intialized // Loop, infinitely, waiting for client connections. - // Stop the program somewhere else. + // If you want to stop or pause the program, go somewhere else. while(true) { - // serverSocket.accept() blocks! then proceeds once a connection is "accept"ed - try (Socket clientConnection = serverSocket.accept()) { // the accept() method blocks here until a client connects + // note that serverSocket.accept() first blocks! then after waiting, execution proceeds once a connection is "accept"ed + // you can check this behavior by using NetBeans Debugger + try (Socket clientConnectionSocket = serverSocket.accept()) { // the accept() method blocks here until a client connects connectionCount++; // got another one! a client has connected - OutputStream os = clientConnection.getOutputStream(); - PrintStream ps = new PrintStream(os); + outputStream = clientConnectionSocket.getOutputStream(); // clientConnectionSocket is new, every time through, so reset the streams + printStream = new PrintStream(outputStream); // if (connectionCount == 1) // first time through, report connection // { // // Where are we? In other words, what is our host number? Advertise it. // // Note that we use the serverSocket to get address, since host may have multiple network connections. // // https://stackoverflow.com/questions/9481865/getting-the-ip-address-of-the-current-machine-using-java -// String localHostAddress = clientConnection.getInetAddress().getHostAddress(); +// String localHostAddress = clientConnectionSocket.getInetAddress().getHostAddress(); // System.out.println("Local host address is " + localHostAddress); +// // add diagnostic for host name, note this might only show up for your system's telnet connection since hostnames aren't part of TCP +// String localHostName = clientConnectionSocket.getInetAddress().getHostName(); +// System.out.println("Local host name is " + localHostName); // if (localHostAddress.contains("/")) // localHostAddress = localHostAddress.substring(localHostAddress.indexOf("/")+1); // // show localhost IP number to facilitate connections over local area network (LAN, WAN) @@ -104,19 +111,19 @@ public class TcpExample2ConnectionCounting // "(telnet " + localHostAddress + " 2317)..." ); // } - ps.println("This client response was written by server " + TcpExample2ConnectionCounting.class.getName()); // to remote client - System.out.println("This server response was written by server " + TcpExample2ConnectionCounting.class.getName()); // to server console + printStream.println("This client response was written by server " + TcpExample2ConnectionCounting.class.getName()); // to remote client + System.out.println("This server response was written by server " + TcpExample2ConnectionCounting.class.getName()); // to server console - ps.println("You were connection #" + connectionCount + ", by my count"); + printStream.println("You were connection #" + connectionCount + ", by my count"); // 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(); + InetAddress localAddress = clientConnectionSocket.getLocalAddress(); + InetAddress remoteAddress = clientConnectionSocket.getInetAddress(); - int localPort = clientConnection.getLocalPort(); - int remotePort = clientConnection.getPort(); // remember the prior question, why are 2 ports different? + int localPort = clientConnectionSocket.getLocalPort(); + int remotePort = clientConnectionSocket.getPort(); // remember the prior question, why are 2 ports different? // 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 )) note IPv6 @@ -125,25 +132,34 @@ public class TcpExample2ConnectionCounting // Why is first IP/port the same, while the second set has different ports? System.out.println("Socket pair (server, client): (( " + localAddress.toString() + ", " + localPort + " ), ( " + - remoteAddress.toString() + ", " + remotePort + " ))"); + remoteAddress.toString() + ", " + remotePort + " ))"); System.out.println("got another connection, #" + connectionCount); // report progress - // 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(); + // Notice the use of flush() to ensure that messages are sent immediately, + // rather than possibly getting buffered for the program's self-perceived efficiency. + outputStream.flush(); + + // Notice the use of optional close() when complete. Without a close() invocation, + // the clientConnectionSocket object may stay open for a while after the client + // has stopped needing this connection. Close() explicitly ends the connection. + // Try hiding this and see if anything different occurs. + clientConnectionSocket.close(); } } } - catch(IOException e) + catch(IOException ioe) { System.err.println("Problem with " + TcpExample2ConnectionCounting.class.getName() + " networking:"); // describe what is happening - System.err.println("Error: " + e); + System.err.println("Error: " + ioe); // Provide more helpful information to user if exception occurs due to running twice at one time - if (e instanceof java.net.BindException) + if (ioe instanceof java.net.BindException) System.err.println("*** Be sure to stop any other running instances of programs using this port!"); } + finally + { + // given the infinite-loop logic above, this step is "hard to reach" but a good practice nevertheless + System.out.println(TcpExample2ConnectionCounting.class.getName() + " has finished, adios!"); + } } } diff --git a/presentations/03_TCPIP.pptx b/presentations/03_TCPIP.pptx index cfeb46d5f8201f8c3a86fb7fef0282772a0ffb6a..0df55519be43aef782da3a3e8254d9073f34c138 100644 Binary files a/presentations/03_TCPIP.pptx and b/presentations/03_TCPIP.pptx differ