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

Merge origin/master

parents b616d7ac e1797f16
No related branches found
No related tags found
No related merge requests found
Showing
with 313 additions and 30 deletions
......@@ -4,14 +4,28 @@ import java.io.*;
import java.net.*;
import java.util.Scanner;
/**
* Client constructor
*/
public class HomeworkClient {
/**
* Client constructor
*/
public HomeworkClient() {
// default constructor
}
/**
* local host
*/
public final static String LOCALHOST = "0:0:0:0:0:0:0:1";
public static void main(String[] args) {
/**
* Client constructor
* @param args passed in args
*/
public static void main(String[] args) {
Socket socket = null;
InputStream is;
Reader isr;
......@@ -19,7 +33,7 @@ public class HomeworkClient {
PrintWriter pw;
String serverMessage;
int clientLoopCount = 0;
Scanner scanner = new Scanner(System.in);
try {
......@@ -42,26 +56,28 @@ public class HomeworkClient {
serverMessage = br.readLine();
System.out.println("==================================================");
System.out.print("Client loop " + clientLoopCount + ": ");
System.out.println("now we're talking!");
System.out.println("The message the server sent was: '" + serverMessage + "'");
Thread.sleep(500l);
}
} catch (IOException | InterruptedException e) {
System.err.println("Problem with " + HomeworkClient.class.getName() + " networking:");
System.err.println("Error: " + e);
if (e instanceof java.net.BindException) {
System.err.println("*** Be sure to stop any other running instances of programs using this port!");
}
} finally {
try {
if (socket != null)
if (socket != null) {
socket.close();
} catch (IOException e) {}
}
} catch (IOException e) {
}
System.out.println();
System.out.println(HomeworkClient.class.getName() + " exit");
}
......
package MV3500Cohort2024JulySeptember.homework1.Smith;
import java.io.*;
import java.net.*;
/**
* Sever constructor
*/
public class HomeworkServer {
private static int runningTotal = 0; // Initialize running total
/**
* Sever constructor
*/
public HomeworkServer() {
// default constructor
}
/**
* main
* @param args passed in args
*/
public static void main(String[] args) {
try {
System.out.println(HomeworkServer.class.getName() + " has started...");
......@@ -31,13 +41,13 @@ public class HomeworkServer {
// Read the number sent by the client
BufferedReader br = new BufferedReader(new InputStreamReader(clientConnectionSocket.getInputStream()));
int clientNumber = Integer.parseInt(br.readLine());
// Update the running total
int clientNumnerSqr = clientNumber * clientNumber;
runningTotal += clientNumber;
// Send back the updated total
ps.println("Client sent: " + clientNumber + ", client number squared was: "+ clientNumnerSqr+", Running total: " + runningTotal);
ps.println("Client sent: " + clientNumber + ", client number squared was: " + clientNumnerSqr + ", Running total: " + runningTotal);
System.out.println("Client sent: " + clientNumber + ", Running total: " + runningTotal);
localAddress = clientConnectionSocket.getLocalAddress();
......@@ -47,13 +57,14 @@ public class HomeworkServer {
System.out.print("Server loop " + serverLoopCount + ": ");
System.out.println(HomeworkServer.class.getName() + " socket pair showing host name, address, port:");
System.out.println(" (( " +
localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( " +
remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))");
if (localAddress.getHostName().equals(localAddress.getHostAddress()) ||
remoteAddress.getHostName().equals(remoteAddress.getHostAddress()))
System.out.println(" note HostName matches address if host has no DNS name");
System.out.println(" (( "
+ localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( "
+ remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))");
if (localAddress.getHostName().equals(localAddress.getHostAddress())
|| remoteAddress.getHostName().equals(remoteAddress.getHostAddress())) {
System.out.println(" note HostName matches address if host has no DNS name");
}
ps.flush();
}
}
......@@ -66,4 +77,3 @@ public class HomeworkServer {
}
}
}
/**
* 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.homework1.Smith;
......@@ -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;
......
/**
* 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.homework1.Timberlake;
/**
* 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.homework1.Williams;
......@@ -8,11 +8,16 @@ import java.net.Socket;
import java.util.Scanner;
/**
*
* This client attempts to connect to a desired server. If the client is unable
* to connect then it exits the program. Enter 'quit' to the command line at any
* time to exit.
* @author tbavlsik
*/
public class BavlsikClient {
/**
* Localhost address.
*/
public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; //Local host
/**
......
......@@ -11,7 +11,7 @@ import java.util.Scanner;
/**
* This client program establishes a socket connection to the {@link LennonHW2DispatchServer},
* then plays a random number guessing game.
* No fancy footwork here, it is pretty simple and similar to {@link TcpExample3Client}.
* No fancy footwork here, it is pretty simple and similar to {TcpExample3Client}.
*
* see TcpExample4DispatchServer
* see TcpExample4HandlerThread
......
......@@ -15,7 +15,7 @@ import java.util.Random;
* 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 TcpExample4DispatchServer} at run time.
* Warning: do not run this class! It is created and used automatically by {@link LennonHW2DispatchServer} at run time.
* </p>
*
* see TcpExample4Client
......
......@@ -8,4 +8,6 @@ Modification to TCPExample4 to ask for a password
Closes once password is entered correctly or incorrectly.
Biggest changes are in the handler thread.
/**
* 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.Matiski;
package MV3500Cohort2024JulySeptember.homework2.Smith;
/**
* This the the rock paper sciccors client.
* @author tjsus
*/
import java.io.*;
import java.net.*;
import java.util.Scanner;
/**
* Client Class
* @author tjsus
*/
public class Client {
/**
* Client constructor
*/
public Client() {
// default constructor
}
/**
* local host
*/
public final static String LOCALHOST = "0:0:0:0:0:0:0:1";
/**
* Main
* @param args passed in args
*/
public static void main(String[] args) {
Socket socket = null;
InputStream is;
......
# 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
package MV3500Cohort2024JulySeptember.homework2.Smith;
/**
* This the the rock paper sciccors server.
* @author tjsus
*/
import java.io.*;
import java.net.*;
import java.util.Random;
/**
* Client Class
* @author tjsus
*/
public class Server {
private static int runningTotal = 0; // Initialize running total
/**
* Server constructor
*/
public Server() {
// default constructor
}
/**
* Main
* @param args passed in args
*/
public static void main(String[] args) {
try {
System.out.println(Server.class.getName() + " has started...");
......
/**
* 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
*/
......
/**
* 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.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