Skip to content
Snippets Groups Projects
Commit 880f24ed authored by Brutzman, Don's avatar Brutzman, Don
Browse files

Merge origin/master

parents bb62d400 a4cb0428
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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;
......
# 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
/**
* 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;
......@@ -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
*/
......
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<>();
......
......@@ -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
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment