diff --git a/MV3500Cohort2021JulySeptember/homework1/Lentz_Python/.gitkeep b/MV3500Cohort2021JulySeptember/homework1/Lentz_Python/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/MV3500Cohort2021JulySeptember/homework1/Lentz_Python/client.py b/MV3500Cohort2021JulySeptember/homework1/Lentz_Python/client.py new file mode 100644 index 0000000000000000000000000000000000000000..3bf853c4108b45a77639d375d7d5db0296124415 --- /dev/null +++ b/MV3500Cohort2021JulySeptember/homework1/Lentz_Python/client.py @@ -0,0 +1,80 @@ +#Adapted from https://github.com/realpython/materials/blob/master/multiconn-client.py +import sys +import socket +import selectors +import types +import contextlib +import os + +with contextlib.suppress(FileNotFoundError): + os.remove('screenshot.png') + +sel = selectors.DefaultSelector() + +def start_connections(host, port, x3d_id): + server_addr = (host, port) + print("starting connection to", server_addr) + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.setblocking(False) + sock.connect_ex(server_addr) + events = selectors.EVENT_READ | selectors.EVENT_WRITE + data = types.SimpleNamespace( + connid=1, + msg_total=sum([1]), + recv_total=0, + messages=[str(x3d_id).encode()], + outb=b"", + ) + sel.register(sock, events, data=data) + + +def service_connection(key, mask): + sock = key.fileobj + data = key.data + if mask & selectors.EVENT_READ: + recv_data = sock.recv(1024) # Should be ready to read + sock.settimeout(None) + if not recv_data: + print("closing connection", data.connid) + sel.unregister(sock) + sock.close() + if recv_data: + with open('screenshot.png','ab') as b: + b.write(recv_data) + data.recv_total += len(recv_data) + print("received " + str(data.recv_total) + " image bytes from connection", data.connid) + + + + + if mask & selectors.EVENT_WRITE: + if not data.outb and data.messages: + data.outb = data.messages.pop(0) + if data.outb: + print("sending", repr(data.outb), "to connection", data.connid) + sent = sock.send(data.outb) # Should be ready to write + data.outb = data.outb[sent:] + + +if len(sys.argv) != 4: + print("This program simulates the agent communicate process where a client requests a dynamically rendered X3D asset from the host.") + print("usage:", sys.argv[0], "<host 192.168.86.225> <port 65500> <x3d asset number [0-14138] >") + sys.exit(1) + +host, port, x3d_id = sys.argv[1:4] +start_connections(host, int(port), int(x3d_id)) + +try: + while True: + events = sel.select(timeout=1) + if events: + for key, mask in events: + service_connection(key, mask) + # Check for a socket being monitored to continue. + if not sel.get_map(): + break +except KeyboardInterrupt: + print("caught keyboard interrupt, exiting") +finally: + sel.close() +sel.close() \ No newline at end of file diff --git a/MV3500Cohort2021JulySeptember/homework1/Lentz_Python/sequence.png b/MV3500Cohort2021JulySeptember/homework1/Lentz_Python/sequence.png new file mode 100644 index 0000000000000000000000000000000000000000..b00a72917b9696b38350f9b45c7bd011743ddf95 Binary files /dev/null and b/MV3500Cohort2021JulySeptember/homework1/Lentz_Python/sequence.png differ diff --git a/MV3500Cohort2021JulySeptember/homework1/Lentz_Python/server.py b/MV3500Cohort2021JulySeptember/homework1/Lentz_Python/server.py new file mode 100644 index 0000000000000000000000000000000000000000..260a999e6ad95e668564e790573db6d6c9ae30de --- /dev/null +++ b/MV3500Cohort2021JulySeptember/homework1/Lentz_Python/server.py @@ -0,0 +1,70 @@ +#Adapted from https://github.com/realpython/materials/blob/master/multiconn-client.py + +import sys +import socket +import selectors +import types +import subprocess +import time + +sel = selectors.DefaultSelector() + + +def accept_wrapper(sock): + conn, addr = sock.accept() # Should be ready to read + print("accepted connection from", addr) + conn.setblocking(False) + data = types.SimpleNamespace(addr=addr, inb=b"", outb=b"") + events = selectors.EVENT_READ | selectors.EVENT_WRITE + sel.register(conn, events, data=data) + + +def service_connection(key, mask): + sock = key.fileobj + data = key.data + if mask & selectors.EVENT_READ: + recv_data = sock.recv(1024) # Should be ready to read + if recv_data: + data.outb += recv_data + else: + print("closing connection to", data.addr) + sel.unregister(sock) + sock.close() + if mask & selectors.EVENT_WRITE: + if data.outb: + fn = data.outb.decode('ascii')+'.x3d' + print( "getting " + fn ) + subprocess.run(["wget", "https://nps.edu/x3d_repository/"+fn,"-O","x3d.x3d"]) + subprocess.run(["/castle_game_engine/bin/view3dscene", "--screenshot","0","screenshot.png","x3d.x3d"]) + png_bytes = open('screenshot.png','rb').read() + print("sending png of length " + str(len(png_bytes)) + ' to ', data.addr) + sent = sock.send(png_bytes) # Should be ready to write + data.outb = png_bytes[sent:] + #time.sleep(5) + #subprocess.run(["rm", "screenshot.png","x3d.x3d"]) + + +if len(sys.argv) != 3: + print("usage:", sys.argv[0], "<host> <port>") + sys.exit(1) + +host, port = sys.argv[1], int(sys.argv[2]) +lsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +lsock.bind((host, port)) +lsock.listen() +print("listening on", (host, port)) +lsock.setblocking(False) +sel.register(lsock, selectors.EVENT_READ, data=None) + +try: + while True: + events = sel.select(timeout=None) + for key, mask in events: + if key.data is None: + accept_wrapper(key.fileobj) + else: + service_connection(key, mask) +except KeyboardInterrupt: + print("caught keyboard interrupt, exiting") +finally: + sel.close() \ No newline at end of file diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankClient.JPG b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankClient.JPG new file mode 100644 index 0000000000000000000000000000000000000000..620c37fabefb933270da0040244d029706887afe Binary files /dev/null and b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankClient.JPG differ diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankClient.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankClient.java new file mode 100644 index 0000000000000000000000000000000000000000..843cb90791f7b72838d87c2ec2f76d7b285790e8 --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankClient.java @@ -0,0 +1,109 @@ +package MV3500Cohort2021JulySeptember.homework2.Frank; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.PrintStream; +import java.io.Reader; +import java.net.Socket; + +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +/** + * + * @author justi + */ +public class FrankClient { + + /** + */ + public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; + + /** + * Program invocation, execution starts here + * + * @param args command-line arguments + * @throws java.lang.InterruptedException + */ + public static void main(String[] args) throws InterruptedException { + + // Local variables/fields + Socket socket = null; + InputStream is; + Reader isr; + BufferedReader br; + String serverMessage; + int clientLoopCount = 0; + OutputStream os; + PrintStream ps; + + + try { + while (true) { + clientLoopCount++; // increment at beginning of loop for reliability + System.out.println( "creating socket..."); + + // We request an IP to connect to ("localhost") and + // port number at that IP (2318). This establishes + // a connection to that IP in the form of a Socket + // object; the server uses a ServerSocket to wait for + // connections. + socket = new Socket(LOCALHOST, 2318); // locohost? + + // Now hook everything up (i.e. set up the streams), Java style: + is = socket.getInputStream(); + isr = new InputStreamReader(is); + br = new BufferedReader(isr); + + // Read a single line written by the server. We'd + // do things a bit differently if there were many lines to be read + // from the server instead of one only. + serverMessage = br.readLine(); + System.out.println("*********************************"); + + System.out.print( clientLoopCount + ": "); + System.out.println("Hola!"); + System.out.println("The message the server sent was: '" + serverMessage + "'"); + + + +// socket gets closed, either automatically/silently by this code (or possibly by the server) + if (serverMessage.equals("this is good bye message from Franks server")) { //if client recieved termanation message stop client + break; + } + os = socket.getOutputStream(); + ps = new PrintStream(os); + ps.println("I'm doing well!"); // this gets sent back to server + ps.flush(); + + Thread.sleep(1000); // turned it down to 1 second + + } // end while(true) // infinite loops are dangerous, be sure to kill this process! + } catch (IOException e) { + System.err.println("Problem with " + FrankClient.class.getName() + " networking:"); // describe what is happening + System.err.println("Error: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } finally // occurs after any other activity when shutting down + { + try { + if (socket != null) { + socket.close(); + } + } catch (IOException e) { + } + + // program exit: tell somebody about that happening. Likely cause: server drops connection. + System.out.println(); + System.out.println("Good Bye!!!"); + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankEventGraph.png b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankEventGraph.png new file mode 100644 index 0000000000000000000000000000000000000000..6d3a798d7b0723d59a70c29ab790c1604a366208 Binary files /dev/null and b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankEventGraph.png differ diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankServer.JPG b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankServer.JPG new file mode 100644 index 0000000000000000000000000000000000000000..d3da29b342839f53571c4a08d1d7d48feb2163d3 Binary files /dev/null and b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankServer.JPG differ diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankServer.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankServer.java new file mode 100644 index 0000000000000000000000000000000000000000..601dee98773668ad0825792b46761da94bf52af8 --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Frank/FrankServer.java @@ -0,0 +1,98 @@ +package MV3500Cohort2021JulySeptember.homework2.Frank; + +import java.io.*; +import java.net.*; + + +public class FrankServer { + + /** + * Program invocation, execution starts here If already compiled, can run + * using console in directory ../../build/classes/ by invoking \ java + * -classpath .TcpExamples.TcpExample3Server + * + * @param args command-line arguments + * @throws java.lang.InterruptedException + */ + public static void main(String[] args) throws InterruptedException { + try { + + // ServerSocket waits for a connection from a client. + // Notice that it is outside the loop; ServerSocket + // needs to be made only once. + System.out.println(FrankServer.class.getName() + " has started..."); // it helps debugging to put this on console first + + ServerSocket serverSocket = new ServerSocket(2318); // changed from 2317 to 2318 + OutputStream os; + PrintStream ps; + InetAddress localAddress, remoteAddress; + int localPort, remotePort; + int serverLoopCount = 0; + InputStream is; + InputStreamReader isr; + BufferedReader br; + String clientMessage; + + // Server is up and waiting (i.e. "blocked" or paused) + // Loop, infinitely, waiting for client connections. + // Stop the program somewhere else. + while (true) { + + // block until connected to a client + try ( Socket clientConnectionSocket = serverSocket.accept()) { + serverLoopCount++; // increment at beginning of loop for reliability + + // Now hook everything up (i.e. set up the streams), Java style: + os = clientConnectionSocket.getOutputStream(); + ps = new PrintStream(os); + if (serverLoopCount <= 10) { // checking if the loop count <= 10 + ps.println("How are you doing?"); // this gets sent back to client! + } else { + ps.println("this is good bye message from Franks server"); // termination after 20 messages + break; // Stop server + } + // Print some information locally about the Socket connection. + // This includes the port and IP numbers on both sides (the socket pair). + localAddress = clientConnectionSocket.getLocalAddress(); + remoteAddress = clientConnectionSocket.getInetAddress(); + localPort = clientConnectionSocket.getLocalPort(); + remotePort = clientConnectionSocket.getPort(); + + System.out.print("Server loop " + serverLoopCount + ": "); + + // 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 )) + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) + // Why is the first IP/port the same, while the second set has different ports? + System.out.println(FrankServer.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"); + } + is = clientConnectionSocket.getInputStream(); + isr = new InputStreamReader(is); + br = new BufferedReader(isr); + clientMessage = br.readLine(); + System.out.println("The message the client sent was: '" + clientMessage + "'");// Displaying the message the client sent + // Not/*i*/ce the use of flush() and try w/ resources. Without + // the try w/ resources the Socket object may stay open for + // a while after the client has stopped needing this + // connection. try w/ resources explicitly ends the connection. + ps.flush(); + // like it or not, you're outta here! + } + } + } catch (IOException e) { + System.err.println("Problem with " + FrankServer.class.getName() + " networking: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankClient.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankClient.java new file mode 100644 index 0000000000000000000000000000000000000000..4f7c74c90157a82ae7a87ea11edeb1505644ab9b --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankClient.java @@ -0,0 +1,99 @@ +package MV3500Cohort2021JulySeptember.homework2; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.Socket; + +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +/** + * + * @author justi + */ +public class FrankClient { + + /** + */ + public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; + + /** + * Program invocation, execution starts here + * + * @param args command-line arguments + * @throws java.lang.InterruptedException + */ + public static void main(String[] args) throws InterruptedException { + + // Local variables/fields + Socket socket = null; + InputStream is; + Reader isr; + BufferedReader br; + String serverMessage; + int clientLoopCount = 0; + + try { + while (true) { + clientLoopCount++; // increment at beginning of loop for reliability + System.out.println( "creating socket..."); + + // We request an IP to connect to ("localhost") and + // port number at that IP (2317). This establishes + // a connection to that IP in the form of a Socket + // object; the server uses a ServerSocket to wait for + // connections. + socket = new Socket(LOCALHOST, 2318); // locohost? + + // Now hook everything up (i.e. set up the streams), Java style: + is = socket.getInputStream(); + isr = new InputStreamReader(is); + br = new BufferedReader(isr); + + // Read a single line written by the server. We'd + // do things a bit differently if there were many lines to be read + // from the server instead of one only. + serverMessage = br.readLine(); + System.out.println("*********************************"); + + System.out.print( clientLoopCount + ": "); + System.out.println("Hola!"); + System.out.println("The message the server sent was: '" + serverMessage + "'"); + int count = 0; + System.out.println("test"); + count++; +// socket gets closed, either automatically/silently by this code (or possibly by the server) + if (serverMessage.equals("this is good bye message from Franks server")) { //if client recieved termanation message stop client + break; + } + Thread.sleep(1000); // turned it down to 1 second + + } // end while(true) // infinite loops are dangerous, be sure to kill this process! + } catch (IOException e) { + System.err.println("Problem with " + FrankClient.class.getName() + " networking:"); // describe what is happening + System.err.println("Error: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } finally // occurs after any other activity when shutting down + { + try { + if (socket != null) { + socket.close(); + } + } catch (IOException e) { + } + + // program exit: tell somebody about that happening. Likely cause: server drops connection. + System.out.println(); + System.out.println("Good Bye!!!"); + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankServer.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankServer.java new file mode 100644 index 0000000000000000000000000000000000000000..6d7fb253e38c748dd99970f504bace3f3452aef2 --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankServer.java @@ -0,0 +1,89 @@ +package MV3500Cohort2021JulySeptember.homework2; + +import java.io.*; +import java.net.*; + + +public class FrankServer { + + /** + * Program invocation, execution starts here If already compiled, can run + * using console in directory ../../build/classes/ by invoking \ java + * -classpath . TcpExamples.TcpExample3Server + * + * @param args command-line arguments + */ + public static void main(String[] args) throws InterruptedException { + try { + + // ServerSocket waits for a connection from a client. + // Notice that it is outside the loop; ServerSocket + // needs to be made only once. + System.out.println(FrankServer.class.getName() + " has started..."); // it helps debugging to put this on console first + + ServerSocket serverSocket = new ServerSocket(2318); // changed from 2317 to 2318 + OutputStream os; + PrintStream ps; + InetAddress localAddress, remoteAddress; + int localPort, remotePort; + int serverLoopCount = 0; + + // Server is up and waiting (i.e. "blocked" or paused) + // Loop, infinitely, waiting for client connections. + // Stop the program somewhere else. + while (true) { + + // block until connected to a client + try ( Socket clientConnectionSocket = serverSocket.accept()) { + serverLoopCount++; // increment at beginning of loop for reliability + + // Now hook everything up (i.e. set up the streams), Java style: + os = clientConnectionSocket.getOutputStream(); + ps = new PrintStream(os); + if (serverLoopCount <= 10) { // checking if the loop count <= 10 + ps.println("How are you doing?"); // this gets sent back to client! + } else { + ps.println("this is good bye message from Franks server"); // termination after 20 messages + break; // Stop server + } + // Print some information locally about the Socket connection. + // This includes the port and IP numbers on both sides (the socket pair). + localAddress = clientConnectionSocket.getLocalAddress(); + remoteAddress = clientConnectionSocket.getInetAddress(); + localPort = clientConnectionSocket.getLocalPort(); + remotePort = clientConnectionSocket.getPort(); + + System.out.print("Server loop " + serverLoopCount + ": "); + + // 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 )) + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) + // Why is the first IP/port the same, while the second set has different ports? + System.out.println(FrankServer.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"); + } + + // Not/*i*/ce the use of flush() and try w/ resources. Without + // the try w/ resources the Socket object may stay open for + // a while after the client has stopped needing this + // connection. try w/ resources explicitly ends the connection. + ps.flush(); + // like it or not, you're outta here! + } + } + } catch (IOException e) { + System.err.println("Problem with " + FrankServer.class.getName() + " networking: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankTcpExample3Client.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankTcpExample3Client.java new file mode 100644 index 0000000000000000000000000000000000000000..31884977d83f96c54aa88b3106fc137020502d85 --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankTcpExample3Client.java @@ -0,0 +1,96 @@ +package MV3500Cohort2021JulySeptember.homework2; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.Socket; + +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +/** + * + * @author justi + */ +public class FrankTcpExample3Client { + + /** + */ + public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; + + /** + * Program invocation, execution starts here + * + * @param args command-line arguments + * @throws java.lang.InterruptedException + */ + public static void main(String[] args) throws InterruptedException { + + // Local variables/fields + Socket socket = null; + InputStream is; + Reader isr; + BufferedReader br; + String serverMessage; + int clientLoopCount = 0; + + try { + while (true) { + clientLoopCount++; // increment at beginning of loop for reliability + System.out.println( "creating socket..."); + + // We request an IP to connect to ("localhost") and + // port number at that IP (2317). This establishes + // a connection to that IP in the form of a Socket + // object; the server uses a ServerSocket to wait for + // connections. + socket = new Socket(LOCALHOST, 2318); // locohost? + + // Now hook everything up (i.e. set up the streams), Java style: + is = socket.getInputStream(); + isr = new InputStreamReader(is); + br = new BufferedReader(isr); + + // Read a single line written by the server. We'd + // do things a bit differently if there were many lines to be read + // from the server instead of one only. + serverMessage = br.readLine(); + System.out.println("*********************************"); + + System.out.print( clientLoopCount + ": "); + System.out.println("Hola!"); + System.out.println("The message the server sent was: '" + serverMessage + "'"); + // socket gets closed, either automatically/silently by this code (or possibly by the server) + if (serverMessage.equals("this is good bye message from Franks server")) { //if client recieved termanation message stop client + break; + } + Thread.sleep(1000); // turned it down to 1 second + + } // end while(true) // infinite loops are dangerous, be sure to kill this process! + } catch (IOException e) { + System.err.println("Problem with " + FrankTcpExample3Client.class.getName() + " networking:"); // describe what is happening + System.err.println("Error: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } finally // occurs after any other activity when shutting down + { + try { + if (socket != null) { + socket.close(); + } + } catch (IOException e) { + } + + // program exit: tell somebody about that happening. Likely cause: server drops connection. + System.out.println(); + System.out.println("Good Bye!!!"); + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankTcpExample3Server.java b/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankTcpExample3Server.java new file mode 100644 index 0000000000000000000000000000000000000000..f292beed04f1b29c108fb5a8e8cfccedb85452bc --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework2/FrankTcpExample3Server.java @@ -0,0 +1,89 @@ +package MV3500Cohort2021JulySeptember.homework2; + +import java.io.*; +import java.net.*; + + +public class FrankTcpExample3Server { + + /** + * Program invocation, execution starts here If already compiled, can run + * using console in directory ../../build/classes/ by invoking \ java + * -classpath . TcpExamples.TcpExample3Server + * + * @param args command-line arguments + */ + public static void main(String[] args) throws InterruptedException { + try { + + // ServerSocket waits for a connection from a client. + // Notice that it is outside the loop; ServerSocket + // needs to be made only once. + System.out.println(FrankTcpExample3Server.class.getName() + " has started..."); // it helps debugging to put this on console first + + ServerSocket serverSocket = new ServerSocket(2318); // changed from 2317 to 2318 + OutputStream os; + PrintStream ps; + InetAddress localAddress, remoteAddress; + int localPort, remotePort; + int serverLoopCount = 0; + + // Server is up and waiting (i.e. "blocked" or paused) + // Loop, infinitely, waiting for client connections. + // Stop the program somewhere else. + while (true) { + + // block until connected to a client + try ( Socket clientConnectionSocket = serverSocket.accept()) { + serverLoopCount++; // increment at beginning of loop for reliability + + // Now hook everything up (i.e. set up the streams), Java style: + os = clientConnectionSocket.getOutputStream(); + ps = new PrintStream(os); + if (serverLoopCount <= 10) { // checking if the loop count <= 10 + ps.println("How are you doing?"); // this gets sent back to client! + } else { + ps.println("this is good bye message from Franks server"); // termination after 20 messages + break; // Stop server + } + // Print some information locally about the Socket connection. + // This includes the port and IP numbers on both sides (the socket pair). + localAddress = clientConnectionSocket.getLocalAddress(); + remoteAddress = clientConnectionSocket.getInetAddress(); + localPort = clientConnectionSocket.getLocalPort(); + remotePort = clientConnectionSocket.getPort(); + + System.out.print("Server loop " + serverLoopCount + ": "); + + // 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 )) + // Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 )) + // Why is the first IP/port the same, while the second set has different ports? + System.out.println(FrankTcpExample3Server.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"); + } + + // Not/*i*/ce the use of flush() and try w/ resources. Without + // the try w/ resources the Socket object may stay open for + // a while after the client has stopped needing this + // connection. try w/ resources explicitly ends the connection. + ps.flush(); + // like it or not, you're outta here! + } + } + } catch (IOException e) { + System.err.println("Problem with " + FrankTcpExample3Server.class.getName() + " networking: " + e); + + // Provide more helpful information to user if exception occurs due to running twice at one time + if (e instanceof java.net.BindException) { + System.err.println("*** Be sure to stop any other running instances of programs using this port!"); + } + } + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework2/Leckie/hw2_Leckie.pdf b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Leckie/hw2_Leckie.pdf new file mode 100644 index 0000000000000000000000000000000000000000..80257d92b0e5f0d9515f9ccbc5643d0c10a62f57 Binary files /dev/null and b/assignments/src/MV3500Cohort2021JulySeptember/homework2/Leckie/hw2_Leckie.pdf differ diff --git a/specifications/downloads/IEEE1278.1-2012.DistributedInteractiveSimulation.ApplicationProtocols.12781-2012.pdf b/specifications/downloads/IEEE1278.1-2012.DistributedInteractiveSimulation.ApplicationProtocols.12781-2012.pdf new file mode 100644 index 0000000000000000000000000000000000000000..88aacbd2671fb41ffd83c38a373574eecff34052 Binary files /dev/null and b/specifications/downloads/IEEE1278.1-2012.DistributedInteractiveSimulation.ApplicationProtocols.12781-2012.pdf differ diff --git a/specifications/downloads/IEEE1278.2-2015.DistributedInteractiveSimulation.CommunicationsServices.12782-2015.pdf b/specifications/downloads/IEEE1278.2-2015.DistributedInteractiveSimulation.CommunicationsServices.12782-2015.pdf new file mode 100644 index 0000000000000000000000000000000000000000..ffc26e3a50d5cdb4d18022ec2353b175d9ba1952 Binary files /dev/null and b/specifications/downloads/IEEE1278.2-2015.DistributedInteractiveSimulation.CommunicationsServices.12782-2015.pdf differ diff --git a/specifications/downloads/IEEE1278.3-2015.DistributedInteractiveSimulation.CommunicationsServices.00587529.pdf b/specifications/downloads/IEEE1278.3-2015.DistributedInteractiveSimulation.CommunicationsServices.00587529.pdf new file mode 100644 index 0000000000000000000000000000000000000000..d8ba28b454f4a9781f26f6671e4257dd82ab5f79 Binary files /dev/null and b/specifications/downloads/IEEE1278.3-2015.DistributedInteractiveSimulation.CommunicationsServices.00587529.pdf differ diff --git a/specifications/downloads/IEEE1278.4-2013.DistributedInteractiveSimulation.VV+A.12784-1997.pdf b/specifications/downloads/IEEE1278.4-2013.DistributedInteractiveSimulation.VV+A.12784-1997.pdf new file mode 100644 index 0000000000000000000000000000000000000000..ddc505e6ed611735f5e47c67be042be0f03f9120 Binary files /dev/null and b/specifications/downloads/IEEE1278.4-2013.DistributedInteractiveSimulation.VV+A.12784-1997.pdf differ