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

Merge origin/master

parents b35c6165 3714ca1d
No related branches found
No related tags found
No related merge requests found
Showing
with 2242 additions and 1814 deletions
source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -114,7 +114,7 @@ manifest.custom.codebase=
manifest.custom.permissions=
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
platform.active=JDK_22
project.licensePath=../license.txt
run.classpath=\
${javac.classpath}:\
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>Networked Graphics MV3500 assignments</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
<spellchecker-wordlist xmlns="http://www.netbeans.org/ns/spellchecker-wordlist/1">
<word>accessor</word>
<word>autogeneration</word>
<word>classpath</word>
<word>deliverables</word>
<word>docx</word>
<word>https</word>
<word>interarrival</word>
<word>javadoc</word>
<word>localhost</word>
<word>multicast</word>
<word>Netbeans</word>
<word>netcat</word>
<word>NPS</word>
<word>pdu</word>
<word>README</word>
<word>simkit</word>
<word>simulationists</word>
<word>SISO</word>
<word>subpackage</word>
<word>teardown</word>
<word>txt</word>
<word>UML</word>
<word>unicast</word>
<word>wikipedia</word>
<word>Wireshark</word>
</spellchecker-wordlist>
</configuration>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>Networked Graphics MV3500 assignments</name>
<explicit-platform explicit-source-supported="true"/>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
<spellchecker-wordlist xmlns="http://www.netbeans.org/ns/spellchecker-wordlist/1">
<word>accessor</word>
<word>autogeneration</word>
<word>classpath</word>
<word>deliverables</word>
<word>docx</word>
<word>https</word>
<word>interarrival</word>
<word>javadoc</word>
<word>localhost</word>
<word>multicast</word>
<word>Netbeans</word>
<word>netcat</word>
<word>NPS</word>
<word>pdu</word>
<word>README</word>
<word>simkit</word>
<word>simulationists</word>
<word>SISO</word>
<word>subpackage</word>
<word>teardown</word>
<word>txt</word>
<word>UML</word>
<word>unicast</word>
<word>wikipedia</word>
<word>Wireshark</word>
</spellchecker-wordlist>
</configuration>
</project>
package MV3500Cohort2024JulySeptember.homework1.Romero;
/**
*
* @author rojas
*/
public class Homework {
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
// TODO code application logic here
}
}
\ No newline at end of file
# Schnitzler Homework 1
***
## Description
Modification of TcpExample1Telnet.java
package MV3500Cohort2024JulySeptember.homework1.Schnitzler;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
/**
*
* @author simonschnitzler
*/
public class SchnitzlerUnicastNetworking {
/** Default constructor */
public SchnitzlerUnicastNetworking()
{
// default constructor
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try
{
System.out.println(SchnitzlerUnicastNetworking.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(" terminal: enter (telnet localhost 2317) or, for macOS (nc localhost 2317) to connect to the socket..." );
// The ServerSocket waits for a connection from a client.
// It returns a Socket object when the connection occurs.
ServerSocket serverSocket = new ServerSocket(2317);
// Use Java io classes to write text (as opposed to
// unknown bytes of some sort) to the client
// The Socket object represents the connection between
// the server and client, including a full duplex connection
try (Socket clientConnection = serverSocket.accept()) // listen, wait here for a client to connect
{
// OK we got something, time to respond!
// Use Java io classes to write text (as opposed to
// unknown bytes of some sort) to the client
OutputStream os = clientConnection.getOutputStream();
PrintStream ps = new PrintStream(os);
ps.println("This client response was written by server " + SchnitzlerUnicastNetworking.class.getName()); // to remote client
System.out.println("This server response was written by server " + SchnitzlerUnicastNetworking.class.getName()); // to server console
// "flush()" in important in that it forces a write
// across what is in fact a slow connection
ps.flush();
}
System.out.println(SchnitzlerUnicastNetworking.class.getName() + " completed successfully.");
}
catch(IOException ioe)
{
System.err.println("Exception with " + SchnitzlerUnicastNetworking.class.getName() + " networking:"); // describe what is happening
System.err.println(ioe);
// Provide more helpful information to user if exception occurs due to running twice at one time
// brute force exception checking, can be brittle if exception message changes
// if (e.getMessage().equals("Address already in use: NET_Bind"))
if (ioe instanceof java.net.BindException)
System.err.println("*** Be sure to stop any other running instances of programs using this port!");
}
}
}
/**
* 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.Schnitzler;
package MV3500Cohort2024JulySeptember.homework1.Smith;
import java.io.*;
import java.net.*;
import java.util.Scanner;
public class HomeworkClient {
public HomeworkClient() {
// default constructor
}
public final static String LOCALHOST = "0:0:0:0:0:0:0:1";
public static void main(String[] args) {
Socket socket = null;
InputStream is;
Reader isr;
BufferedReader br;
PrintWriter pw;
String serverMessage;
int clientLoopCount = 0;
Scanner scanner = new Scanner(System.in);
try {
while (true) {
clientLoopCount++;
System.out.println(HomeworkClient.class.getName() + " creating socket...");
socket = new Socket(LOCALHOST, 2317);
System.out.println("Enter a number to send to the server:");
int numberToSend = scanner.nextInt();
// Send the number to the server
pw = new PrintWriter(socket.getOutputStream(), true);
pw.println(numberToSend);
is = socket.getInputStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
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)
socket.close();
} catch (IOException e) {}
System.out.println();
System.out.println(HomeworkClient.class.getName() + " exit");
}
}
}
package MV3500Cohort2024JulySeptember.homework1.Smith;
import java.io.*;
import java.net.*;
public class HomeworkServer {
private static int runningTotal = 0; // Initialize running total
public HomeworkServer() {
// default constructor
}
public static void main(String[] args) {
try {
System.out.println(HomeworkServer.class.getName() + " has started...");
ServerSocket serverSocket = new ServerSocket(2317);
OutputStream os;
PrintStream ps;
InetAddress localAddress, remoteAddress;
int localPort, remotePort;
int serverLoopCount = 0;
while (true) {
try (Socket clientConnectionSocket = serverSocket.accept()) {
serverLoopCount++;
os = clientConnectionSocket.getOutputStream();
ps = new PrintStream(os);
// 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);
System.out.println("Client sent: " + clientNumber + ", Running total: " + runningTotal);
localAddress = clientConnectionSocket.getLocalAddress();
remoteAddress = clientConnectionSocket.getInetAddress();
localPort = clientConnectionSocket.getLocalPort();
remotePort = clientConnectionSocket.getPort();
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");
ps.flush();
}
}
} catch (IOException e) {
System.err.println("Problem with " + HomeworkServer.class.getName() + " networking: " + e);
if (e instanceof java.net.BindException) {
System.err.println("*** Be sure to stop any other running instances of programs using this port!");
}
}
}
}
package MV3500Cohort2024JulySeptember.homework1.Williams;
import java.io.*;
import java.net.*;
import java.util.Scanner;
public class Client {
public Client() {
// default constructor
}
public final static String LOCALHOST = "127.0.0.1"; // localhost IP address
public static void main(String[] args) {
Socket socket = null;
int clientLoopCount = 0;
Scanner scanner = new Scanner(System.in);
try {
while (true) {
clientLoopCount++;
System.out.println(Client.class.getName() + " creating socket...");
socket = new Socket(LOCALHOST, 2317);
System.out.println("Enter a number to send to the server (or type 'exit' to quit):");
String input = scanner.next();
if ("exit".equalsIgnoreCase(input)) {
break;
}
int numberToSend;
try {
numberToSend = Integer.parseInt(input);
} catch (NumberFormatException e) {
System.out.println("Invalid input. Please enter a valid number.");
continue;
}
// Send the number to the server
try (PrintWriter pw = new PrintWriter(socket.getOutputStream(), true); BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()))) {
pw.println(numberToSend);
String 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 + "'");
} catch (IOException e) {
System.err.println("Error sending/receiving data: " + e.getMessage());
}
Thread.sleep(500L);
}
} catch (IOException | InterruptedException e) {
System.err.println("Problem with " + Client.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 {
if (socket != null && !socket.isClosed()) {
try {
socket.close();
} catch (IOException e) {
System.err.println("Error closing socket: " + e.getMessage());
}
}
scanner.close();
System.out.println();
System.out.println(Client.class.getName() + " exit");
}
}
}
package MV3500Cohort2024JulySeptember.homework1.Williams;
import java.io.*;
import java.net.*;
public class Server {
private static int runningTotal = 0; // Initialize running total
public Server() {
// default constructor
}
public static void main(String[] args) {
try {
System.out.println(Server.class.getName() + " has started...");
ServerSocket serverSocket = new ServerSocket(2317);
int serverLoopCount = 0;
while (true) {
try (Socket clientConnectionSocket = serverSocket.accept(); BufferedReader br = new BufferedReader(new InputStreamReader(clientConnectionSocket.getInputStream())); PrintStream ps = new PrintStream(clientConnectionSocket.getOutputStream())) {
serverLoopCount++;
// Read the number sent by the client
String input = br.readLine();
if (input == null) {
System.err.println("Received null input, skipping this client.");
continue;
}
int clientNumber;
try {
clientNumber = Integer.parseInt(input);
} catch (NumberFormatException e) {
System.err.println("Invalid input received: " + input + ". Error: " + e.getMessage());
ps.println("Invalid number format: " + input);
continue;
}
// Update the running total
int clientNumberSqr = clientNumber * clientNumber;
runningTotal += clientNumber;
// Send back the updated total and squared number
ps.println("Client sent: " + clientNumber + ", client number squared was: " + clientNumberSqr + ", Running total: " + runningTotal);
System.out.println("Client sent: " + clientNumber + ", Running total: " + runningTotal);
InetAddress localAddress = clientConnectionSocket.getLocalAddress();
InetAddress remoteAddress = clientConnectionSocket.getInetAddress();
int localPort = clientConnectionSocket.getLocalPort();
int remotePort = clientConnectionSocket.getPort();
System.out.print("Server loop " + serverLoopCount + ": ");
System.out.println(Server.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");
}
} catch (IOException e) {
System.err.println("Problem handling client connection: " + e.getMessage());
}
}
} catch (IOException e) {
System.err.println("Problem with " + Server.class.getName() + " networking: " + e);
if (e instanceof java.net.BindException) {
System.err.println("*** Be sure to stop any other running instances of programs using this port!");
}
}
}
}
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