diff --git a/assignments/src/MV3500Cohort2024JulySeptember/homework1/Timberlake/Client.java b/assignments/src/MV3500Cohort2024JulySeptember/homework1/Timberlake/Client.java index d905f89d60ba8046d823ca966cca61692c9f8bd0..e5e366e17270abd2283a21941efae98e0ab2b981 100644 --- a/assignments/src/MV3500Cohort2024JulySeptember/homework1/Timberlake/Client.java +++ b/assignments/src/MV3500Cohort2024JulySeptember/homework1/Timberlake/Client.java @@ -6,10 +6,56 @@ import java.net.InetAddress; import java.util.Scanner; /** - * - * @author Jack + * <p> + * The simplest TCP network program, opening a socket between a client and server + * and send a message from the client to the server. + * It listens for any socket connection response, either from telnet (telnet localhost 2317) + * or another client program. + * Once a socket connection is established, the client sends messages to the + * server and the server echos the message back to the client. + * + * <p> + * As an alternative to running the Windows (or other operating system) console, + * you can instead run the NetBeans terminal window. If you are on Windows, + * NetBeans is looking for Cygwin installation (for Unix-like compatibility) + * with details at <a href="https://savage.nps.edu/Savage/developers.html#Cygwin" target="blank">Savage Developers Guide: Cygwin</a>. + * Modifying this program is the basis for Assignment 1. + * </p> + + * <p> + * Notice that "Client Received" matches + * what is written by the code below, over the output stream. + * </p> + * * <p> + * Notice that "Server Received" matches the string sent by the client. + * </p> + * <p> + * After the echoed message is received by the client, the program exits. + * For example: + * Enter message to send to server: hello + * Client received: Hello From Server, I received: hello + * [Program Exits] + * </p> + * + * @see <a href="../../../src/TcpExamples/TcpExample1TerminalLog.txt" target="_blank">TcpExample1TerminalLog.txt</a> + * @see <a href="../../../src/TcpExamples/TcpExample1NetBeansConsoleTelnet.png" target="_blank">TcpExample1NetBeansConsoleTelnet.png</a> + * @see <a href="../../../src/TcpExamples/TcpExample1NetBeansConsoleTelnet.pdf" target="_blank">TcpExample1NetBeansConsoleTelnet.pdf</a> + * @see <a href="../../../src/TcpExamples/TcpExample1ScreenshotNetcat.png" target="_blank">TcpExample1ScreenshotNetcat.png</a> + * @see <a href="../../../src/TcpExamples/TcpExample1ScreenshotTelnet.png" target="_blank">TcpExample1ScreenshotTelnet.png</a> + * @see <a href="https://savage.nps.edu/Savage/developers.html#Cygwin" target="blank">Savage Developers Guide: Cygwin</a> + * @see <a href="https://savage.nps.edu/Savage/developers.html#telnet" target="blank">Savage Developers Guide: telnet</a> + * + * @author mcgredo + * @author brutzman@nps.edu + * @author james.timberlake@nps.edu */ public class Client { + + /** + * Default constructor + * Program invocation, execution starts here + * @param args command-line arguments + */ public static void main(String[] args) { DatagramSocket socket = null; Scanner scanner = new Scanner(System.in); diff --git a/assignments/src/MV3500Cohort2024JulySeptember/homework1/Timberlake/Server.java b/assignments/src/MV3500Cohort2024JulySeptember/homework1/Timberlake/Server.java index 54b88a994bcad4a4313adad0f55ce44cd0910a05..c9cae31dc13da3679282630cfedccecff7a43af5 100644 --- a/assignments/src/MV3500Cohort2024JulySeptember/homework1/Timberlake/Server.java +++ b/assignments/src/MV3500Cohort2024JulySeptember/homework1/Timberlake/Server.java @@ -5,10 +5,56 @@ import java.net.DatagramSocket; import java.net.InetAddress; /** - * - * @author Jack + * <p> + * The simplest TCP network program, opening a socket between a client and server + * and send a message from the client to the server. + * It listens for any socket connection response, either from telnet (telnet localhost 2317) + * or another client program. + * Once a socket connection is established, the client sends messages to the + * server and the server echos the message back to the client. + * + * <p> + * As an alternative to running the Windows (or other operating system) console, + * you can instead run the NetBeans terminal window. If you are on Windows, + * NetBeans is looking for Cygwin installation (for Unix-like compatibility) + * with details at <a href="https://savage.nps.edu/Savage/developers.html#Cygwin" target="blank">Savage Developers Guide: Cygwin</a>. + * Modifying this program is the basis for Assignment 1. + * </p> + + * <p> + * Notice that "Client Received" matches + * what is written by the code below, over the output stream. + * </p> + * * <p> + * Notice that "Server Received" matches the string sent by the client. + * </p> + * <p> + * After the echoed message is received by the client, the program exits. + * For example: + * Enter message to send to server: hello + * Client received: Hello From Server, I received: hello + * [Program Exits] + * </p> + * + * @see <a href="../../../src/TcpExamples/TcpExample1TerminalLog.txt" target="_blank">TcpExample1TerminalLog.txt</a> + * @see <a href="../../../src/TcpExamples/TcpExample1NetBeansConsoleTelnet.png" target="_blank">TcpExample1NetBeansConsoleTelnet.png</a> + * @see <a href="../../../src/TcpExamples/TcpExample1NetBeansConsoleTelnet.pdf" target="_blank">TcpExample1NetBeansConsoleTelnet.pdf</a> + * @see <a href="../../../src/TcpExamples/TcpExample1ScreenshotNetcat.png" target="_blank">TcpExample1ScreenshotNetcat.png</a> + * @see <a href="../../../src/TcpExamples/TcpExample1ScreenshotTelnet.png" target="_blank">TcpExample1ScreenshotTelnet.png</a> + * @see <a href="https://savage.nps.edu/Savage/developers.html#Cygwin" target="blank">Savage Developers Guide: Cygwin</a> + * @see <a href="https://savage.nps.edu/Savage/developers.html#telnet" target="blank">Savage Developers Guide: telnet</a> + * + * @author mcgredo + * @author brutzman@nps.edu + * @author james.timberlake@nps.edu */ public class Server { + + /** + * Default constructor + * Program invocation, execution starts here + * @param args none + */ public static void main(String[] args) { DatagramSocket socket = null; diff --git a/assignments/src/MV3500Cohort2024JulySeptember/homework2/Smith/README.md b/assignments/src/MV3500Cohort2024JulySeptember/homework2/Smith/README.md new file mode 100644 index 0000000000000000000000000000000000000000..ea7585b7e94c797c6dae0e9e4c59dc50b0d6b727 --- /dev/null +++ b/assignments/src/MV3500Cohort2024JulySeptember/homework2/Smith/README.md @@ -0,0 +1,10 @@ +# Smith Homework 2 + +*** + +## Description +Modification of TcpExample3 and adding some code to implement a rock, paper, sciccors game with a client. + +The 'Server' class sets up a server that listens for incoming client connections. + +The 'Client' class connects to a server running on localhost. It sends user input from the console to the server and displays messages received from the server. \ No newline at end of file diff --git a/assignments/src/MV3500Cohort2024JulySeptember/homework2/Smith/package-info.java b/assignments/src/MV3500Cohort2024JulySeptember/homework2/Smith/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..194b250d511cd953662daf6870f44b969e443cb3 --- /dev/null +++ b/assignments/src/MV3500Cohort2024JulySeptember/homework2/Smith/package-info.java @@ -0,0 +1,10 @@ +/** + * TCP Unicast homework assignments supporting the NPS MOVES MV3500 Networked Graphics course. + * + * @see <a href="https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/-/tree/master/assignments" target="_blank">networkedGraphicsMV3500 assignments</a> + * @see java.lang.Package + * @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 MV3500Cohort2024JulySeptember.homework2.Smith; diff --git a/assignments/src/MV3500Cohort2024JulySeptember/homework2/Timberlake/Client_HW2.java b/assignments/src/MV3500Cohort2024JulySeptember/homework2/Timberlake/Client_HW2.java index 806d4bee9ad3e4f909819bf3d1a87053f755be23..aab58250d6a1f91ff76375126ab287212cd5c38a 100644 --- a/assignments/src/MV3500Cohort2024JulySeptember/homework2/Timberlake/Client_HW2.java +++ b/assignments/src/MV3500Cohort2024JulySeptember/homework2/Timberlake/Client_HW2.java @@ -8,8 +8,21 @@ import java.util.Scanner; import java.io.PrintWriter; /** + * This client program establishes a socket connection to the {@link GameHandler.java}, + * then plays a random number guessing game. + * No fancy footwork here, it is pretty simple and similar to {@link TcpExample3Client}. + * + * see TcpExample4DispatchServer + * see TcpExample4HandlerThread * - * @author Jack + * @see <a href="../../../src/TcpExamples/TcpExample4TerminalLog.txt" target="blank">TcpExample4TerminalLog.txt</a> + * @see <a href="../../../src/TcpExamples/TcpExample4SequenceDiagram.png" target="blank">TcpExample4SequenceDiagram.png</a> + * @see <a href="../../../src/TcpExamples/TcpExample4SequenceSketch.png" target="blank">TcpExample4SequenceSketch.png</a> + * + * @author Don McGregor + * @author Don Brutzman + * @author MV3500 class + * @author Jack Timberlake */ diff --git a/assignments/src/MV3500Cohort2024JulySeptember/homework2/Timberlake/GameHandler.java b/assignments/src/MV3500Cohort2024JulySeptember/homework2/Timberlake/GameHandler.java index 9403aa23e5602254321633278d8e3ceb1a6dca8f..403a68b58b2ee0e0a528d3e63b40d96b6b2e2aed 100644 --- a/assignments/src/MV3500Cohort2024JulySeptember/homework2/Timberlake/GameHandler.java +++ b/assignments/src/MV3500Cohort2024JulySeptember/homework2/Timberlake/GameHandler.java @@ -1,8 +1,28 @@ package MV3500Cohort2024JulySeptember.homework2.Timberlake; /** + * <p> + * This utility class supports the {@link Server_HW2} program, + * handling all programming logic needed for a new socket connection + * to run in a thread of its own. This is the server + * portion as well, so we artificially invent what happens + * if the server can't respond to a connection for several seconds. + * </p> + * <p> + * Warning: do not run this class! It is created and used automatically by {@link Server_HW2} at run time. + * </p> + * + * see Server_HW2 + * see Client_HW2 * - * @author Jack + * @see <a href="../../../src/TcpExamples/TcpExample4TerminalLog.txt" target="blank">TcpExample4TerminalLog.txt</a> + * @see <a href="../../../src/TcpExamples/TcpExample4SequenceDiagram.png" target="blank">TcpExample4SequenceDiagram.png</a> + * @see <a href="../../../src/TcpExamples/TcpExample4SequenceSketch.png" target="blank">TcpExample4SequenceSketch.png</a> + * + * @author Don McGregor + * @author Don Brutzman + * @author MV3500 class + * @author Jack Timberlake */ import java.io.BufferedReader; @@ -14,6 +34,12 @@ import java.util.HashMap; import java.util.Map; public class GameHandler implements Runnable { + /** + * The thread constructor creates the socket from a ServerSocket, waiting for the client to connect, + * and passes that socket when constructing the thread responsible for handling the connection. + * + * @param socket The socket connection handled by this thread + */ private Socket clientSocket; private int numToGuess; private static final Map<String, String> userCredentials = new HashMap<>(); diff --git a/assignments/src/MV3500Cohort2024JulySeptember/homework2/Timberlake/Server_HW2.java b/assignments/src/MV3500Cohort2024JulySeptember/homework2/Timberlake/Server_HW2.java index 987e79ec35af26cddb82cc8c5b53a889101993a3..36ed7fa156d1c6f7b6fbc568214f51ce66937633 100644 --- a/assignments/src/MV3500Cohort2024JulySeptember/homework2/Timberlake/Server_HW2.java +++ b/assignments/src/MV3500Cohort2024JulySeptember/homework2/Timberlake/Server_HW2.java @@ -4,8 +4,21 @@ import java.net.ServerSocket; import java.net.Socket; /** + * This server program works a bit differently by creating and dispatching a + * new thread to handle multiple incoming socket connections, one after another, all running in parallel. + * This advanced technique is often used in high=performance high=capacity server programs. + * + * @see Client_HW2 + * @see GameHandler * - * @author Jack + * @see <a href="../../../src/TcpExamples/TcpExample4TerminalLog.txt" target="blank">TcpExample4TerminalLog.txt</a> + * @see <a href="../../../src/TcpExamples/TcpExample4SequenceDiagram.png" target="blank">TcpExample4SequenceDiagram.png</a> + * @see <a href="../../../src/TcpExamples/TcpExample4SequenceSketch.png" target="blank">TcpExample4SequenceSketch.png</a> + * + * @author Don McGregor + * @author Don Brutzman + * @author MV3500 class + * @author Jack Timberlake */