diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Cannon/CannonReceivingSendingScreenshots.pdf b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Cannon/CannonReceivingSendingScreenshots.pdf new file mode 100644 index 0000000000000000000000000000000000000000..f8999ad7cd6af4f5270ed9c4c22962ae4057b5ea Binary files /dev/null and b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Cannon/CannonReceivingSendingScreenshots.pdf differ diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Cannon/CannonUdpReceiver.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Cannon/CannonUdpReceiver.java new file mode 100644 index 0000000000000000000000000000000000000000..dfbb3430f83c30674323d55bd78a063562248eb2 --- /dev/null +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Cannon/CannonUdpReceiver.java @@ -0,0 +1,92 @@ +package MV3500Cohort2020JulySeptember.homework3.Cannon; + +import java.io.*; +import java.net.*; + +/** + * An example of receiving UDP packets. Since very often both the + * sender and receiver are on the same host we use different ports + * for each. This prevents collision complaints from the localhost. + * + * Start this before launching UdpSender. + * + * @see https://docs.oracle.com/javase/tutorial/essential/io/datastreams.html + * @see https://en.wikipedia.org/wiki/User_Datagram_Protocol + * @author mcgredo + * @author brutzman + */ +public class CannonUdpReceiver +{ +// public static final int SENDING_PORT = 1414; // port used by UdpSender, unneeded here + public static final int RECEIVING_PORT = 1415; + public static final String DESINATION_HOST = "localhost"; + + /** + * @param args the command line arguments + * @throws java.io.IOException + */ + public static void main(String[] args) throws IOException + { + DatagramSocket udpSocket = null; + + try + { + System.out.println(CannonUdpReceiver.class.getName() + " started..."); + + // Create a UDP socket + udpSocket = new DatagramSocket(RECEIVING_PORT); + udpSocket.setReceiveBufferSize(1500); // how many bytes are in buffer? MTU=1500 is good + udpSocket.setBroadcast(false); // we're just receiving here + + byte[] byteArray = new byte[1500]; + DatagramPacket receivePacket = new DatagramPacket(byteArray, byteArray.length); + + ByteArrayInputStream bais = new ByteArrayInputStream(byteArray); + DataInputStream dis = new DataInputStream(bais); + + boolean isEvenParity; + int packetCount = 0; + int firstInt; + float secondFloat; + String thirdString; + String padding; + + // You need a new receiving packet to read from every packet received + while (true) + { + packetCount++; // good practice to increment counter at start of loop, when possible + udpSocket.receive(receivePacket); // blocks until packet is received + + // values of interest follow. order and types of what was sent must match what you are reading! + firstInt = dis.readInt(); // packetID + secondFloat = dis.readFloat(); + thirdString = dis.readUTF(); // string value with guaranteed encoding, matches UTF-8 is 8 bit + isEvenParity = dis.readBoolean(); // ok, we've gotten everything we're looking for. + + dis.reset(); // now clear the input stream after reading, in preparation for next loop + + if (isEvenParity) + padding = " "; + else padding = ""; + + System.out.println("[" + CannonUdpReceiver.class.getName() + "]" + + " packetID=" + firstInt + // have output message use same name as sender + ", second float value=" + secondFloat + + ", third String value=\"" + thirdString + "\"" + // note that /" is literal quote character + " isPacketIdEvenParity=" + isEvenParity + "," + padding + + " packet counter=" + packetCount); + } + } + catch(IOException e) + { + System.err.println("Problem with UdpReceiver, see exception trace:"); + System.err.println(e); + } + finally // clean up prior to exit, don't want to leave behind zombie socket + { + if (udpSocket != null) + udpSocket.close(); + System.out.println(CannonUdpReceiver.class.getName() + " complete."); // all done + } + } +} diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Cannon/CannonUdpSender.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Cannon/CannonUdpSender.java new file mode 100644 index 0000000000000000000000000000000000000000..471f5e0c49b35e0b6ca23906e218d26faf2b6ce9 --- /dev/null +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Cannon/CannonUdpSender.java @@ -0,0 +1,115 @@ +package MV3500Cohort2020JulySeptember.homework3.Cannon; + +import java.io.*; +import java.net.*; + +/** + * An example of sending UDP packets. The sending and receiving programs + * use different UDP ports; there can be problems getting this to work + * if both the sending and receiving sockets try to use the same port + * on the same host. + * + * Start this before launching UdpReceiver. + * + * @see https://docs.oracle.com/javase/tutorial/essential/io/datastreams.html + * @see https://en.wikipedia.org/wiki/User_Datagram_Protocol + * @author mcgredo + * @author brutzman + */ +public class CannonUdpSender +{ + // System properties: https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html + public static final String MY_NAME = System.getProperty("user.name"); // guru incantation 8) +// public static final int SENDING_PORT = 1414; // not needed, can let system choose an open local port + public static final int RECEIVING_PORT = 1415; + public static final int TOTAL_PACKETS_TO_SEND = 100; + + // here is what we need for lab comms + public static final String DESTINATION_HOST = "10.1.105.7"; // localhost 127.0.0.1 or argon 10.1.105.1 or 10.1.105.1 or whatever + + @SuppressWarnings("SleepWhileInLoop") + public static void main(String[] args) throws IOException + { + DatagramSocket udpSocket = null; + DataOutputStream dos = null; + int packetID = 0; // counter variable to send in packet + float value = -1.0f; // unreachable value is good sentinel to ensure expected changes occur + String message = MY_NAME + " says we need to understand llamas in order to code"; // no really + String padding = new String(); + + try + { + System.out.println(CannonUdpSender.class.getName() + " shows how to send simple-type values via DataOutputStream"); + System.out.println(CannonUdpSender.class.getName() + " started..."); + + // Create a UDP socket + udpSocket = new DatagramSocket(); // let system assign output port, then SENDING_PORT not needed + + // Put together a message with binary content. "ByteArrayOutputStream" + // is a java.io utility that lets us put together an array of binary + // data, which we put into the UDP packet. + + ByteArrayOutputStream baos = new ByteArrayOutputStream(1500); // how many bytes are in buffer? MTU=1500 is good + dos = new DataOutputStream(baos); // wrapper for writing values, connects both streams + + // Put together a packet to send + // these types and order of variables must match on sender and receiver + byte[] byteArray = baos.toByteArray(); + + // ID of the host we are sending to + InetAddress destinationAddress = InetAddress.getByName(DESTINATION_HOST); + // ID of the host we are sending from + InetAddress sourceAddress = InetAddress.getByName("localhost"); // possibly identical if source not modified + + DatagramPacket datagramPacket = new DatagramPacket(byteArray, byteArray.length, destinationAddress, RECEIVING_PORT); + + // Hmmm, how fast does UDP stream go? Does UDP effectively slow packets down, or does + // this cause network problems? (hint: yes for an unlimited send rate, unlike TCP). + // How do you know on the receiving side that you haven't received a + // duplicate UDP packet, out-of-order packet, or dropped packet? your responsibility. + + for (int index = 1; index <= TOTAL_PACKETS_TO_SEND; index++) // avoid infinite send loops in code, they can be hard to kill! + { + packetID++; // increment counter, prefer using explicit value to index + value = TOTAL_PACKETS_TO_SEND - packetID; // countdown + boolean isPacketIdEvenParity = ((packetID % 2) == 0); // % is modulo operator; result 0 is even parity, 1 is odd parity + + // values of interest follow. order and types of what was sent must match what you are reading! + dos.writeInt (packetID); + dos.writeFloat (value); + dos.writeUTF (message); // string value with guaranteed encoding, matches UTF-8 is 8 bit + dos.writeBoolean(isPacketIdEvenParity); + + dos.flush(); // sends DataOutputStream to ByteArrayOutputStream + byteArray = baos.toByteArray(); // OK so go get the flushed result... + datagramPacket.setData(byteArray); // and put it in the packet... + udpSocket.send(datagramPacket); // and send it away. boom gone, nonblocking. +// System.out.println("udpSocket output port=" + udpSocket.getLocalPort()); // diagnostic tells what port was chosen by system + + if (isPacketIdEvenParity) + padding = " "; + else padding = ""; + + Thread.sleep(1000); // Send packets at rate of one per second + System.out.println("[" + CannonUdpSender.class.getName() + "] " + MY_NAME + " " + sourceAddress + + " sent values(" + packetID + "," + value + ",\"" + message + "\"," + isPacketIdEvenParity + + ")" + padding + " as packet #" + index + " of " + TOTAL_PACKETS_TO_SEND); + baos.reset(); // clear the output stream after sending + } + } + catch (IOException | InterruptedException e) + { + System.err.println("Problem with UdpSender, see exception trace:"); + System.err.println(e); + } + finally // clean up prior to exit, don't want to leave behind zombies + { + if (udpSocket != null) + udpSocket.close(); + + if (dos != null) + dos.close(); + System.out.println(CannonUdpSender.class.getName() + " complete."); // all done + } + } +} diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Garibay/Garibay_Receiving_Message_Screenshot.png b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Garibay/Garibay_Receiving_Message_Screenshot.png new file mode 100644 index 0000000000000000000000000000000000000000..cbb912bab6c489924bd319693efa221e551c5fcc Binary files /dev/null and b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Garibay/Garibay_Receiving_Message_Screenshot.png differ diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Garibay/Garibay_Sending_Message_Screenshot.png b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Garibay/Garibay_Sending_Message_Screenshot.png new file mode 100644 index 0000000000000000000000000000000000000000..b92d41084c8cc01b4fce816f91a2e5d1d2cfb467 Binary files /dev/null and b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Garibay/Garibay_Sending_Message_Screenshot.png differ diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Garibay/UDPReceiverGaribay.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Garibay/UDPReceiverGaribay.java new file mode 100644 index 0000000000000000000000000000000000000000..29a74cea5ae6d55fbde366c3b31d7ab288e1bff6 --- /dev/null +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Garibay/UDPReceiverGaribay.java @@ -0,0 +1,88 @@ + +package MV3500Cohort2020JulySeptember.homework3.Garibay; + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; + +/** + * + * @author chris + */ +public class UDPReceiverGaribay +{ +// public static final int SENDING_PORT = 1414; // port used by UdpSender, unneeded here + public static final int RECEIVING_PORT = 1415; + public static final String DESINATION_HOST = "localhost"; + + /** + * @param args the command line arguments + * @throws java.io.IOException + */ + public static void main(String[] args) throws IOException + { + DatagramSocket udpSocket = null; + + try + { + System.out.println(UDPReceiverGaribay.class.getName() + " started..."); + + // Create a UDP socket + udpSocket = new DatagramSocket(RECEIVING_PORT); + udpSocket.setReceiveBufferSize(1500); // how many bytes are in buffer? MTU=1500 is good + udpSocket.setBroadcast(false); // we're just receiving here + + byte[] byteArray = new byte[1500]; + DatagramPacket receivePacket = new DatagramPacket(byteArray, byteArray.length); + + ByteArrayInputStream bais = new ByteArrayInputStream(byteArray); + DataInputStream dis = new DataInputStream(bais); + + boolean isEvenParity; + int packetCount = 0; + int firstInt; + float secondFloat; + String thirdString; + String padding; + + // You need a new receiving packet to read from every packet received + while (true) + { + packetCount++; // good practice to increment counter at start of loop, when possible + udpSocket.receive(receivePacket); // blocks until packet is received + + // values of interest follow. order and types of what was sent must match what you are reading! + firstInt = dis.readInt(); // packetID + secondFloat = dis.readFloat(); + thirdString = dis.readUTF(); // string value with guaranteed encoding, matches UTF-8 is 8 bit + isEvenParity = dis.readBoolean(); // ok, we've gotten everything we're looking for. + + dis.reset(); // now clear the input stream after reading, in preparation for next loop + + if (isEvenParity) + padding = " "; + else padding = ""; + + System.out.println("[" + UDPReceiverGaribay.class.getName() + "]" + + " packetID=" + firstInt + // have output message use same name as sender + ", second float value=" + secondFloat + + ", third String value=\"" + thirdString + "\"" + // note that /" is literal quote character + " isPacketIdEvenParity=" + isEvenParity + "," + padding + + " packet counter=" + packetCount); + } + } + catch(IOException e) + { + System.err.println("Problem with UdpReceiver, see exception trace:"); + System.err.println(e); + } + finally // clean up prior to exit, don't want to leave behind zombie socket + { + if (udpSocket != null) + udpSocket.close(); + System.out.println(UDPReceiverGaribay.class.getName() + " complete."); // all done + } + } +} diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Garibay/UDPSenderGaribay.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Garibay/UDPSenderGaribay.java new file mode 100644 index 0000000000000000000000000000000000000000..8d6a81c06dd090f9d281f90818551cfed1c50a11 --- /dev/null +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Garibay/UDPSenderGaribay.java @@ -0,0 +1,112 @@ + +package MV3500Cohort2020JulySeptember.homework3.Garibay; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; + +/** + * + * @author chris + */ +public class UDPSenderGaribay +{ + // System properties: https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html + public static final String MY_NAME = System.getProperty("user.name"); // guru incantation 8) +// public static final int SENDING_PORT = 1414; // not needed, can let system choose an open local port + public static final int RECEIVING_PORT = 1415; + public static final int TOTAL_PACKETS_TO_SEND = 100; + + // here is what we need for lab comms + // Bill Mahan's host ip + public static final String DESTINATION_HOST = "10.1.105.13"; // localhost 127.0.0.1 or argon 10.1.105.1 or 10.1.105.1 or whatever + + @SuppressWarnings("SleepWhileInLoop") + public static void main(String[] args) throws IOException + { + DatagramSocket udpSocket = null; + DataOutputStream dos = null; + int packetID = 0; // counter variable to send in packet + float value = -1.0f; // unreachable value is good sentinel to ensure expected changes occur + String message = MY_NAME + "It's not a trick question!"; // no really + String padding = new String(); + + try + { + System.out.println(UDPSenderGaribay.class.getName() + " shows how to send simple-type values via DataOutputStream"); + System.out.println(UDPSenderGaribay.class.getName() + " started..."); + + // Create a UDP socket + udpSocket = new DatagramSocket(); // let system assign output port, then SENDING_PORT not needed + + // Put together a message with binary content. "ByteArrayOutputStream" + // is a java.io utility that lets us put together an array of binary + // data, which we put into the UDP packet. + + ByteArrayOutputStream baos = new ByteArrayOutputStream(1500); // how many bytes are in buffer? MTU=1500 is good + dos = new DataOutputStream(baos); // wrapper for writing values, connects both streams + + // Put together a packet to send + // these types and order of variables must match on sender and receiver + byte[] byteArray = baos.toByteArray(); + + // ID of the host we are sending to + InetAddress destinationAddress = InetAddress.getByName(DESTINATION_HOST); + // ID of the host we are sending from + InetAddress sourceAddress = InetAddress.getByName("localhost"); // possibly identical if source not modified + + DatagramPacket datagramPacket = new DatagramPacket(byteArray, byteArray.length, destinationAddress, RECEIVING_PORT); + + // Hmmm, how fast does UDP stream go? Does UDP effectively slow packets down, or does + // this cause network problems? (hint: yes for an unlimited send rate, unlike TCP). + // How do you know on the receiving side that you haven't received a + // duplicate UDP packet, out-of-order packet, or dropped packet? your responsibility. + + for (int index = 1; index <= TOTAL_PACKETS_TO_SEND; index++) // avoid infinite send loops in code, they can be hard to kill! + { + packetID++; // increment counter, prefer using explicit value to index + value = TOTAL_PACKETS_TO_SEND - packetID; // countdown + boolean isPacketIdEvenParity = ((packetID % 2) == 0); // % is modulo operator; result 0 is even parity, 1 is odd parity + + // values of interest follow. order and types of what was sent must match what you are reading! + dos.writeInt (packetID); + dos.writeFloat (value); + dos.writeUTF (message); // string value with guaranteed encoding, matches UTF-8 is 8 bit + dos.writeBoolean(isPacketIdEvenParity); + + dos.flush(); // sends DataOutputStream to ByteArrayOutputStream + byteArray = baos.toByteArray(); // OK so go get the flushed result... + datagramPacket.setData(byteArray); // and put it in the packet... + udpSocket.send(datagramPacket); // and send it away. boom gone, nonblocking. +// System.out.println("udpSocket output port=" + udpSocket.getLocalPort()); // diagnostic tells what port was chosen by system + + if (isPacketIdEvenParity) + padding = " "; + else padding = ""; + + Thread.sleep(1000); // Send packets at rate of one per second + System.out.println("[" + UDPSenderGaribay.class.getName() + "] " + MY_NAME + " " + sourceAddress + + " sent values(" + packetID + "," + value + ",\"" + message + "\"," + isPacketIdEvenParity + + ")" + padding + " as packet #" + index + " of " + TOTAL_PACKETS_TO_SEND); + baos.reset(); // clear the output stream after sending + } + } + catch (IOException | InterruptedException e) + { + System.err.println("Problem with UDPSenderGaribay, see exception trace:"); + System.err.println(e); + } + finally // clean up prior to exit, don't want to leave behind zombies + { + if (udpSocket != null) + udpSocket.close(); + + if (dos != null) + dos.close(); + System.out.println(UDPSenderGaribay.class.getName() + " complete."); // all done + } + } +} diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Goericke/TCPNumberReceiverUDPResultSender.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Goericke/TCPNumberReceiverUDPResultSender.java new file mode 100644 index 0000000000000000000000000000000000000000..f9a58490506bf9d40d70cc31b3ce1bc758f87e24 --- /dev/null +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Goericke/TCPNumberReceiverUDPResultSender.java @@ -0,0 +1,176 @@ +package MV3500Cohort2020JulySeptember.homework3.Goericke; + +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; + +/** + * This class will be connected by an TCP sender over VPN (argon), calculating + * a result of an equation and send the result back via UDP over VPN. + * @date 08/17/2020 + * @group Goericke/Weissenberger + */ +public class TCPNumberReceiverUDPResultSender { + + // Change this to the port where the TCP server is listening + private static final int TCP_ARGON_SERVER_PORT = 2317; + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + try { + + // ServerSocket waits for a connection from a client. + System.out.println("TCPNumberReceiver has started..."); + ServerSocket serverSocket = new ServerSocket(TCP_ARGON_SERVER_PORT); + InetAddress remoteAddress; + + // declare the stream and readers + InputStream inputStream; + InputStreamReader inputStreamReader; + BufferedReader bufferedReader; + + // declare needed variables + String clientMessage; + int number1, number2; + String calculation_Method; + int iUDPResultReceivingPort; + // Server is up and waiting (i.e. "blocked" or paused) + // Loop, infinitely, waiting for client connections. + while (true) { + + // block until connected to a client + try (Socket clientConnectionSocket = serverSocket.accept()) + { + // Now hook everything up (i.e. set up the streams), Java style: + inputStream = clientConnectionSocket.getInputStream(); + inputStreamReader = new InputStreamReader(inputStream); + bufferedReader = new BufferedReader(inputStreamReader); + + // get the date from TCP packet + clientMessage = bufferedReader.readLine(); + number1 = Integer.parseInt(bufferedReader.readLine()); + number2 = Integer.parseInt(bufferedReader.readLine()); + calculation_Method = bufferedReader.readLine(); + iUDPResultReceivingPort = Integer.parseInt(bufferedReader.readLine()); + + // print them out (for debugging) + System.out.println("Message recived: "+clientMessage); + System.out.println("Number 1 recived: "+number1); + System.out.println("Number 2 recived: "+number2); + System.out.println("Calc Method recived: "+calculation_Method); + System.out.println("Send result to port: "+iUDPResultReceivingPort); + // get the sender IP (is used for sending UDP) + remoteAddress = clientConnectionSocket.getInetAddress(); + + System.out.println("Send result to IP: "+remoteAddress.getHostAddress()); + + // try to send the calculated result as a float via UDP... + sendResultViaUDP(calculateResult(number1, number2, calculation_Method), remoteAddress, iUDPResultReceivingPort); + } + } + } catch (IOException e) { + System.err.println("Problem with TcpExample3Server 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!"); + } + } + } + + /** + * send the result to Bernd 10x + * @param result + * @param inetAddress Bernd's IP + * @param port Bernd's UDP port number + * @throws IOException + */ + private static void sendResultViaUDP(float result, InetAddress inetAddress, int port) throws IOException{ + DatagramSocket udpSocket = null; + DataOutputStream dos = null; + + try + { + // Create a UDP socket + udpSocket = new DatagramSocket(); // let system assign output port, then SENDING_PORT not needed + + // Put together a message with binary content. "ByteArrayOutputStream" + // is a java.io utility that lets us put together an array of binary + // data, which we put into the UDP packet. + + ByteArrayOutputStream baos = new ByteArrayOutputStream(1500); // how many bytes are in buffer? MTU=1500 is good + dos = new DataOutputStream(baos); // wrapper for writing values, connects both streams + + // Put together a packet to send + // these types and order of variables must match on sender and receiver + byte[] byteArray = baos.toByteArray(); + + DatagramPacket datagramPacket = new DatagramPacket(byteArray, byteArray.length, inetAddress, port); + + for (int index = 1; index <= 10; index++) + { + dos.writeFloat (result); + dos.flush(); // sends DataOutputStream to ByteArrayOutputStream + byteArray = baos.toByteArray(); // OK so go get the flushed result... + datagramPacket.setData(byteArray); // and put it in the packet... + udpSocket.send(datagramPacket); // and send it away. boom gone, nonblocking. + + Thread.sleep(1000); // Send packets at rate of one per second + baos.reset(); // clear the output stream after sending + } + dos.close(); + } + catch (IOException | InterruptedException e) + { + System.err.println("Problem with UdpSender, see exception trace:"); + System.err.println(e); + } + finally // clean up prior to exit, don't want to leave behind zombies + { + if (udpSocket != null) + udpSocket.close(); + + if (dos != null) + dos.close(); + } + } + + /** + * calculates the result based on given numbers and operator + * @param n1 first number + * @param n2 second number + * @param operator + * @return the result as a float + */ + private static float calculateResult(int n1, int n2, String operator){ + float result = -1; + switch (operator) { + case "+": + result = n1 + n2; + break; + case "-": + result = n1 - n2; + break; + case "*": + result = n1 * n2; + break; + case "/": + result = n1 / n2; + break; + default: + System.err.println(operator +" is not a valid operator!"); + break; + } + return result; + } +} diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Mahan/MahanUdpReceiver.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Mahan/MahanUdpReceiver.java new file mode 100644 index 0000000000000000000000000000000000000000..7d7ca1757bf7b15d90f93c3d16e2f1fd5570ae38 --- /dev/null +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Mahan/MahanUdpReceiver.java @@ -0,0 +1,84 @@ +package MV3500Cohort2020JulySeptember.homework3.Mahan; + +import java.io.*; +import java.net.*; + +/** + * + * @author Bill + */ +public class MahanUdpReceiver +{ +// public static final int SENDING_PORT = 1414; // port used by UdpSender, unneeded here + public static final int RECEIVING_PORT = 1415; + public static final String DESINATION_HOST = "10.1.105.12"; + + /** + * @param args the command line arguments + * @throws java.io.IOException + */ + public static void main(String[] args) throws IOException + { + DatagramSocket udpSocket = null; + + try + { + System.out.println(MahanUdpReceiver.class.getName() + " started..."); + + // Create a UDP socket + udpSocket = new DatagramSocket(RECEIVING_PORT); + udpSocket.setReceiveBufferSize(1500); // how many bytes are in buffer? MTU=1500 is good + udpSocket.setBroadcast(false); // we're just receiving here + + byte[] byteArray = new byte[1500]; + DatagramPacket receivePacket = new DatagramPacket(byteArray, byteArray.length); + + ByteArrayInputStream bais = new ByteArrayInputStream(byteArray); + DataInputStream dis = new DataInputStream(bais); + + boolean isEvenParity; + int packetCount = 0; + int firstInt; + float secondFloat; + String thirdString; + String padding; + + // You need a new receiving packet to read from every packet received + while (true) + { + packetCount++; // good practice to increment counter at start of loop, when possible + udpSocket.receive(receivePacket); // blocks until packet is received + + // values of interest follow. order and types of what was sent must match what you are reading! + firstInt = dis.readInt(); // packetID + secondFloat = dis.readFloat(); + thirdString = dis.readUTF(); // string value with guaranteed encoding, matches UTF-8 is 8 bit + isEvenParity = dis.readBoolean(); // ok, we've gotten everything we're looking for. + + dis.reset(); // now clear the input stream after reading, in preparation for next loop + + if (isEvenParity) + padding = " "; + else padding = ""; + + System.out.println("[" + MahanUdpReceiver.class.getName() + "]" + + " packetID=" + firstInt + // have output message use same name as sender + ", second float value=" + secondFloat + + ", third String value=\"" + thirdString + "\"" + // note that /" is literal quote character + " isPacketIdEvenParity=" + isEvenParity + "," + padding + + " packet counter=" + packetCount); + } + } + catch(IOException e) + { + System.err.println("Problem with UdpReceiver, see exception trace:"); + System.err.println(e); + } + finally // clean up prior to exit, don't want to leave behind zombie socket + { + if (udpSocket != null) + udpSocket.close(); + System.out.println(MahanUdpReceiver.class.getName() + " complete."); // all done + } + } +} diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Mahan/MahanUdpSender.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Mahan/MahanUdpSender.java new file mode 100644 index 0000000000000000000000000000000000000000..199cbd5217bd2e9ce943a7df983686dc3ed3a474 --- /dev/null +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Mahan/MahanUdpSender.java @@ -0,0 +1,106 @@ +package MV3500Cohort2020JulySeptember.homework3.Mahan; + +import java.io.*; +import java.net.*; + +/** + * + * @author Bill + */ +public class MahanUdpSender +{ + // System properties: https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html + public static final String MY_NAME = System.getProperty("user.name"); // guru incantation 8) +// public static final int SENDING_PORT = 1414; // not needed, can let system choose an open local port + public static final int RECEIVING_PORT = 1415; + public static final int TOTAL_PACKETS_TO_SEND = 100; + + // here is what we need for lab comms + public static final String DESTINATION_HOST = "10.1.105.12"; // localhost 127.0.0.1 or argon 10.1.105.1 or 10.1.105.1 or whatever + + @SuppressWarnings("SleepWhileInLoop") + public static void main(String[] args) throws IOException + { + DatagramSocket udpSocket = null; + DataOutputStream dos = null; + int packetID = 0; // counter variable to send in packet + float value = -1.0f; // unreachable value is good sentinel to ensure expected changes occur + String message = MY_NAME + " says I see you Chris"; // no really + String padding = new String(); + + try + { + System.out.println(MahanUdpSender.class.getName() + " shows how to send simple-type values via DataOutputStream"); + System.out.println(MahanUdpSender.class.getName() + " started..."); + + // Create a UDP socket + udpSocket = new DatagramSocket(); // let system assign output port, then SENDING_PORT not needed + + // Put together a message with binary content. "ByteArrayOutputStream" + // is a java.io utility that lets us put together an array of binary + // data, which we put into the UDP packet. + + ByteArrayOutputStream baos = new ByteArrayOutputStream(1500); // how many bytes are in buffer? MTU=1500 is good + dos = new DataOutputStream(baos); // wrapper for writing values, connects both streams + + // Put together a packet to send + // these types and order of variables must match on sender and receiver + byte[] byteArray = baos.toByteArray(); + + // ID of the host we are sending to + InetAddress destinationAddress = InetAddress.getByName(DESTINATION_HOST); + // ID of the host we are sending from + InetAddress sourceAddress = InetAddress.getByName("localhost"); // possibly identical if source not modified + + DatagramPacket datagramPacket = new DatagramPacket(byteArray, byteArray.length, destinationAddress, RECEIVING_PORT); + + // Hmmm, how fast does UDP stream go? Does UDP effectively slow packets down, or does + // this cause network problems? (hint: yes for an unlimited send rate, unlike TCP). + // How do you know on the receiving side that you haven't received a + // duplicate UDP packet, out-of-order packet, or dropped packet? your responsibility. + + for (int index = 1; index <= TOTAL_PACKETS_TO_SEND; index++) // avoid infinite send loops in code, they can be hard to kill! + { + packetID++; // increment counter, prefer using explicit value to index + value = TOTAL_PACKETS_TO_SEND - packetID; // countdown + boolean isPacketIdEvenParity = ((packetID % 2) == 0); // % is modulo operator; result 0 is even parity, 1 is odd parity + + // values of interest follow. order and types of what was sent must match what you are reading! + dos.writeInt (packetID); + dos.writeFloat (value); + dos.writeUTF (message); // string value with guaranteed encoding, matches UTF-8 is 8 bit + dos.writeBoolean(isPacketIdEvenParity); + + dos.flush(); // sends DataOutputStream to ByteArrayOutputStream + byteArray = baos.toByteArray(); // OK so go get the flushed result... + datagramPacket.setData(byteArray); // and put it in the packet... + udpSocket.send(datagramPacket); // and send it away. boom gone, nonblocking. +// System.out.println("udpSocket output port=" + udpSocket.getLocalPort()); // diagnostic tells what port was chosen by system + + if (isPacketIdEvenParity) + padding = " "; + else padding = ""; + + Thread.sleep(1000); // Send packets at rate of one per second + System.out.println("[" + MahanUdpSender.class.getName() + "] " + MY_NAME + " " + sourceAddress + + " sent values(" + packetID + "," + value + ",\"" + message + "\"," + isPacketIdEvenParity + + ")" + padding + " as packet #" + index + " of " + TOTAL_PACKETS_TO_SEND); + baos.reset(); // clear the output stream after sending + } + } + catch (IOException | InterruptedException e) + { + System.err.println("Problem with UdpSender, see exception trace:"); + System.err.println(e); + } + finally // clean up prior to exit, don't want to leave behind zombies + { + if (udpSocket != null) + udpSocket.close(); + + if (dos != null) + dos.close(); + System.out.println(MahanUdpSender.class.getName() + " complete."); // all done + } + } +} diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Mahan/receiving screenshot.png b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Mahan/receiving screenshot.png new file mode 100644 index 0000000000000000000000000000000000000000..b92d41084c8cc01b4fce816f91a2e5d1d2cfb467 Binary files /dev/null and b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Mahan/receiving screenshot.png differ diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Mahan/sendingscreenshot.png b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Mahan/sendingscreenshot.png new file mode 100644 index 0000000000000000000000000000000000000000..cbb912bab6c489924bd319693efa221e551c5fcc Binary files /dev/null and b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Mahan/sendingscreenshot.png differ diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/Screenshots.docx b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/Screenshots.docx new file mode 100644 index 0000000000000000000000000000000000000000..ccb72d8a6b6bf96522119ec8837209f50fba9496 Binary files /dev/null and b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/Screenshots.docx differ diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/TCPNumberSender.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/TCPNumberSender.java new file mode 100644 index 0000000000000000000000000000000000000000..8985ce40b6af5f0cbf8a5a2f3a183fa3edd20bef --- /dev/null +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/TCPNumberSender.java @@ -0,0 +1,97 @@ + +package MV3500Cohort2020JulySeptember.homework3.Weissenberger; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; +import java.net.Socket; + +/** + * This class will connect to an TCP receiver over VPN (argon) and send + * two numbers + * @date 08/17/2020 + * @author Loki + * @group Weissenberger/Goericke + */ +public class TCPNumberSender { + + // Change this to the IP address of the TCP server 10.1.105.9 (127.0.0.1 just for testing) + private static final String TCP_ARGON_SERVER_IP = "127.0.0.1"; + // Change this to the port where the TCP server is listening + private static final int TCP_ARGON_SERVER_PORT = 2317; + // Where the result should be posted (port) + private static final int UDP_ARGON_RECEIVING_PORT = 1415; + + private static final int NUMBER1 = 16; + private static final int NUMBER2 = 2; + private static final String CALCULATION_METHOD = "-"; + + // how many times should the number being sent + private static final int REPETITION = 1; + private static int counter = 0; + + public static void main(String[] args) throws InterruptedException { + + // Local variables + Socket socket; + OutputStream outputStream; + PrintStream printStream; + + try { + while (counter < REPETITION){ + // increment the counter + counter++; + System.out.println("Homwork 3: TcpNumberSender creating socket over VPN..."); + + // We request an IP to connect to "TCP_ARGON_SERVER_IP" over + // the argon VPN and port number at that IP "TCP_ARGON_SERVER_PORT". + // This establishes a connection to that IP in the form of a Socket + // object. + socket = new Socket(TCP_ARGON_SERVER_IP, TCP_ARGON_SERVER_PORT); // locohost? + + + // instanciate the streams: + outputStream = socket.getOutputStream(); + printStream = new PrintStream(outputStream); + // send a first text to server + printStream.println("This is message from client."); + printStream.flush(); + // wait 1 second + Thread.sleep(1000); + + // sending number 1 + printStream.println(NUMBER1); + // sending number 2 + printStream.println(NUMBER2); + // sending calc method + printStream.println(CALCULATION_METHOD); + // sending the port where the result should be send to + printStream.println(UDP_ARGON_RECEIVING_PORT); + printStream.flush(); + // wait 1 second + Thread.sleep(1000); + + System.out.println("=================================================="); + System.out.println(NUMBER1+" and "+NUMBER2+" were sent to server. Calculating method was: "+CALCULATION_METHOD); + + // close TCP socket to server + socket.close(); + } // end while(true) + } + catch (IOException e) + { + System.err.println("Problem with TCPNumberSender 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: "+TCP_ARGON_SERVER_PORT); + } + } + finally // occurs after any other activity when shutting down + { + System.out.println(); + System.out.println("TCPNumberSender exit"); + } + } + +} diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/UDPResultReceiver.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/UDPResultReceiver.java new file mode 100644 index 0000000000000000000000000000000000000000..8a348e72d82e6c0861d02896e489f24faa9239e1 --- /dev/null +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/UDPResultReceiver.java @@ -0,0 +1,71 @@ + +package MV3500Cohort2020JulySeptember.homework3.Weissenberger; + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; + +/** + * This class will be connected by an UDP sender over VPN (argon) + * @date 08/17/2020 + * @author Loki + * @group Weissenberger/Goericke + */ +public class UDPResultReceiver { + + public static final int RECEIVING_PORT = 1415; + + /** + * @param args the command line arguments + * @throws java.io.IOException + */ + public static void main(String[] args) throws IOException + { + DatagramSocket udpSocket = null; + + try + { + System.out.println(UDPResultReceiver.class.getName() + " started..."); + + // Create a UDP socket + udpSocket = new DatagramSocket(RECEIVING_PORT); + udpSocket.setReceiveBufferSize(1500); // how many bytes are in buffer? MTU=1500 is good + udpSocket.setBroadcast(false); // we're just receiving here + + byte[] byteArray = new byte[1500]; + DatagramPacket receivePacket = new DatagramPacket(byteArray, byteArray.length); + + ByteArrayInputStream bais = new ByteArrayInputStream(byteArray); + DataInputStream dis = new DataInputStream(bais); + + float result; + + // You need a new receiving packet to read from every packet received + while (true) + { + udpSocket.receive(receivePacket); // blocks until packet is received + + result = dis.readFloat(); + + dis.reset(); // now clear the input stream after reading, in preparation for next loop + + System.out.println("Calculated result: "+result); + + } + } + catch(IOException e) + { + System.err.println("Problem with UdpReceiver, see exception trace:"); + System.err.println(e); + } + finally // clean up prior to exit, don't want to leave behind zombie socket + { + if (udpSocket != null) + udpSocket.close(); + System.out.println(UDPResultReceiver.class.getName() + " complete."); // all done + } + } + +} diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/logic.jpg b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/logic.jpg new file mode 100644 index 0000000000000000000000000000000000000000..5fa827094c869ea38ad6d265395843694f0263b8 Binary files /dev/null and b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/logic.jpg differ diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/logic.vsdx b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/logic.vsdx new file mode 100644 index 0000000000000000000000000000000000000000..4d2e6878bd82a1d201bc8f4742ff1a67d4cc5f34 Binary files /dev/null and b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/logic.vsdx differ diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/sequence.jpg b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/sequence.jpg new file mode 100644 index 0000000000000000000000000000000000000000..44faf01bb3a35a5d7072c8705529f2ef73deecd7 Binary files /dev/null and b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/sequence.jpg differ diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/sequence.vsdx b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/sequence.vsdx new file mode 100644 index 0000000000000000000000000000000000000000..c43b2fe02d509af09eead57cd0180a2e5d5f1567 Binary files /dev/null and b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/sequence.vsdx differ diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/README.md b/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/README.md new file mode 100644 index 0000000000000000000000000000000000000000..3ec21e2b976a5937ab94a80cb4028ccb79441eae --- /dev/null +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/README.md @@ -0,0 +1,39 @@ +## Homework 2: Multicast Networking + +Modify this file to describe your project work. + +Typical deliverables include properly packages source, execution log, and screen shots as appropriate. + +References include +* [README.md](../README.md) for this homework project. +* [README.md](../../../../README.md) for course assignments execution instructions. +* [assignments source subdirectories](../../../../../assignments/src) show examples from previous cohorts. + +Questions and innovation are always welcome, good luck! + + + +************************************************** +Project for HW #3 +Team: "Germany" (Stefan and Bernd) +************************************************** + + + +This program(s) do(es) the following: +- send two numbers, a mathematical operator and a port number over VPN to a TCP receiver +- the TCP receiver calculates the result and send it back to the sender over VPN using UDP! +- the UDP receiver shows the result + +The main focus was to send via TCP over a VPN, do something and send the result back via UDP. + +How to run the project: +0. connect both computer with the argon net +1. run UDPResultReceiver on Bernd's computer +2. run TCPNumberReceiverUDPResultSender on Stefan's computer +3. find Stefan's IP within the argon net +4. change the TCP_ARGON_SERVER_IP in class TCPNumberSender to Stefan's IP. +5. run TCPNumberSender + +(you can edit the numbers and run TCPNumberSender multiple times...) + diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/Screenshots.docx b/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/Screenshots.docx new file mode 100644 index 0000000000000000000000000000000000000000..ccb72d8a6b6bf96522119ec8837209f50fba9496 Binary files /dev/null and b/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/Screenshots.docx differ diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/TCPNumberReceiverUDPResultSender.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/TCPNumberReceiverUDPResultSender.java new file mode 100644 index 0000000000000000000000000000000000000000..14ac299c8a175857436a6989babc2a83a7575896 --- /dev/null +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/TCPNumberReceiverUDPResultSender.java @@ -0,0 +1,176 @@ +package MV3500Cohort2020JulySeptember.homework3.WeissenbergerGoericke; + +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; + +/** + * This class will be connected by an TCP sender over VPN (argon), calculating + * a result of an equation and send the result back via UDP over VPN. + * @date 08/17/2020 + * @group Goericke/Weissenberger + */ +public class TCPNumberReceiverUDPResultSender { + + // Change this to the port where the TCP server is listening + private static final int TCP_ARGON_SERVER_PORT = 2317; + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + try { + + // ServerSocket waits for a connection from a client. + System.out.println("TCPNumberReceiver has started..."); + ServerSocket serverSocket = new ServerSocket(TCP_ARGON_SERVER_PORT); + InetAddress remoteAddress; + + // declare the stream and readers + InputStream inputStream; + InputStreamReader inputStreamReader; + BufferedReader bufferedReader; + + // declare needed variables + String clientMessage; + int number1, number2; + String calculation_Method; + int iUDPResultReceivingPort; + // Server is up and waiting (i.e. "blocked" or paused) + // Loop, infinitely, waiting for client connections. + while (true) { + + // block until connected to a client + try (Socket clientConnectionSocket = serverSocket.accept()) + { + // Now hook everything up (i.e. set up the streams), Java style: + inputStream = clientConnectionSocket.getInputStream(); + inputStreamReader = new InputStreamReader(inputStream); + bufferedReader = new BufferedReader(inputStreamReader); + + // get the date from TCP packet + clientMessage = bufferedReader.readLine(); + number1 = Integer.parseInt(bufferedReader.readLine()); + number2 = Integer.parseInt(bufferedReader.readLine()); + calculation_Method = bufferedReader.readLine(); + iUDPResultReceivingPort = Integer.parseInt(bufferedReader.readLine()); + + // print them out (for debugging) + System.out.println("Message recived: "+clientMessage); + System.out.println("Number 1 recived: "+number1); + System.out.println("Number 2 recived: "+number2); + System.out.println("Calc Method recived: "+calculation_Method); + System.out.println("Send result to port: "+iUDPResultReceivingPort); + // get the sender IP (is used for sending UDP) + remoteAddress = clientConnectionSocket.getInetAddress(); + + System.out.println("Send result to IP: "+remoteAddress.getHostAddress()); + + // try to send the calculated result as a float via UDP... + sendResultViaUDP(calculateResult(number1, number2, calculation_Method), remoteAddress, iUDPResultReceivingPort); + } + } + } catch (IOException e) { + System.err.println("Problem with TcpExample3Server 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!"); + } + } + } + + /** + * send the result to Bernd 10x + * @param result + * @param inetAddress Bernd's IP + * @param port Bernd's UDP port number + * @throws IOException + */ + private static void sendResultViaUDP(float result, InetAddress inetAddress, int port) throws IOException{ + DatagramSocket udpSocket = null; + DataOutputStream dos = null; + + try + { + // Create a UDP socket + udpSocket = new DatagramSocket(); // let system assign output port, then SENDING_PORT not needed + + // Put together a message with binary content. "ByteArrayOutputStream" + // is a java.io utility that lets us put together an array of binary + // data, which we put into the UDP packet. + + ByteArrayOutputStream baos = new ByteArrayOutputStream(1500); // how many bytes are in buffer? MTU=1500 is good + dos = new DataOutputStream(baos); // wrapper for writing values, connects both streams + + // Put together a packet to send + // these types and order of variables must match on sender and receiver + byte[] byteArray = baos.toByteArray(); + + DatagramPacket datagramPacket = new DatagramPacket(byteArray, byteArray.length, inetAddress, port); + + for (int index = 1; index <= 10; index++) + { + dos.writeFloat (result); + dos.flush(); // sends DataOutputStream to ByteArrayOutputStream + byteArray = baos.toByteArray(); // OK so go get the flushed result... + datagramPacket.setData(byteArray); // and put it in the packet... + udpSocket.send(datagramPacket); // and send it away. boom gone, nonblocking. + + Thread.sleep(1000); // Send packets at rate of one per second + baos.reset(); // clear the output stream after sending + } + dos.close(); + } + catch (IOException | InterruptedException e) + { + System.err.println("Problem with UdpSender, see exception trace:"); + System.err.println(e); + } + finally // clean up prior to exit, don't want to leave behind zombies + { + if (udpSocket != null) + udpSocket.close(); + + if (dos != null) + dos.close(); + } + } + + /** + * calculates the result based on given numbers and operator + * @param n1 first number + * @param n2 second number + * @param operator + * @return the result as a float + */ + private static float calculateResult(int n1, int n2, String operator){ + float result = -1; + switch (operator) { + case "+": + result = n1 + n2; + break; + case "-": + result = n1 - n2; + break; + case "*": + result = n1 * n2; + break; + case "/": + result = n1 / n2; + break; + default: + System.err.println(operator +" is not a valid operator!"); + break; + } + return result; + } +} diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/TCPNumberSender.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/TCPNumberSender.java new file mode 100644 index 0000000000000000000000000000000000000000..b84a10f1b7da60f66fd938f4aafce52f684ba3d8 --- /dev/null +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/TCPNumberSender.java @@ -0,0 +1,97 @@ + +package MV3500Cohort2020JulySeptember.homework3.WeissenbergerGoericke; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; +import java.net.Socket; + +/** + * This class will connect to an TCP receiver over VPN (argon) and send + * two numbers + * @date 08/17/2020 + * @author Loki + * @group Weissenberger/Goericke + */ +public class TCPNumberSender { + + // Change this to the IP address of the TCP server 10.1.105.10 (127.0.0.1 just for testing) + private static final String TCP_ARGON_SERVER_IP = "10.1.105.10"; + // Change this to the port where the TCP server is listening + private static final int TCP_ARGON_SERVER_PORT = 2317; + // Where the result should be posted (port) + private static final int UDP_ARGON_RECEIVING_PORT = 1415; + + private static final int NUMBER1 = 16; + private static final int NUMBER2 = 2; + private static final String CALCULATION_METHOD = "-"; + + // how many times should the number being sent + private static final int REPETITION = 1; + private static int counter = 0; + + public static void main(String[] args) throws InterruptedException { + + // Local variables + Socket socket; + OutputStream outputStream; + PrintStream printStream; + + try { + while (counter < REPETITION){ + // increment the counter + counter++; + System.out.println("Homwork 3: TcpNumberSender creating socket over VPN..."); + + // We request an IP to connect to "TCP_ARGON_SERVER_IP" over + // the argon VPN and port number at that IP "TCP_ARGON_SERVER_PORT". + // This establishes a connection to that IP in the form of a Socket + // object. + socket = new Socket(TCP_ARGON_SERVER_IP, TCP_ARGON_SERVER_PORT); // locohost? + + + // instanciate the streams: + outputStream = socket.getOutputStream(); + printStream = new PrintStream(outputStream); + // send a first text to server + printStream.println("This is message from client."); + printStream.flush(); + // wait 1 second + Thread.sleep(1000); + + // sending number 1 + printStream.println(NUMBER1); + // sending number 2 + printStream.println(NUMBER2); + // sending calc method + printStream.println(CALCULATION_METHOD); + // sending the port where the result should be send to + printStream.println(UDP_ARGON_RECEIVING_PORT); + printStream.flush(); + // wait 1 second + Thread.sleep(1000); + + System.out.println("=================================================="); + System.out.println(NUMBER1+" and "+NUMBER2+" were sent to server. Calculating method was: "+CALCULATION_METHOD); + + // close TCP socket to server + socket.close(); + } // end while(true) + } + catch (IOException e) + { + System.err.println("Problem with TCPNumberSender 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: "+TCP_ARGON_SERVER_PORT); + } + } + finally // occurs after any other activity when shutting down + { + System.out.println(); + System.out.println("TCPNumberSender exit"); + } + } + +} diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/UDPResultReceiver.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/UDPResultReceiver.java new file mode 100644 index 0000000000000000000000000000000000000000..1a181820810e24c66cfc6465fdb58824fad30e74 --- /dev/null +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/UDPResultReceiver.java @@ -0,0 +1,71 @@ + +package MV3500Cohort2020JulySeptember.homework3.WeissenbergerGoericke; + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; + +/** + * This class will be connected by an UDP sender over VPN (argon) + * @date 08/17/2020 + * @author Loki + * @group Weissenberger/Goericke + */ +public class UDPResultReceiver { + + public static final int RECEIVING_PORT = 1415; + + /** + * @param args the command line arguments + * @throws java.io.IOException + */ + public static void main(String[] args) throws IOException + { + DatagramSocket udpSocket = null; + + try + { + System.out.println(UDPResultReceiver.class.getName() + " started..."); + + // Create a UDP socket + udpSocket = new DatagramSocket(RECEIVING_PORT); + udpSocket.setReceiveBufferSize(1500); // how many bytes are in buffer? MTU=1500 is good + udpSocket.setBroadcast(false); // we're just receiving here + + byte[] byteArray = new byte[1500]; + DatagramPacket receivePacket = new DatagramPacket(byteArray, byteArray.length); + + ByteArrayInputStream bais = new ByteArrayInputStream(byteArray); + DataInputStream dis = new DataInputStream(bais); + + float result; + + // You need a new receiving packet to read from every packet received + while (true) + { + udpSocket.receive(receivePacket); // blocks until packet is received + + result = dis.readFloat(); + + dis.reset(); // now clear the input stream after reading, in preparation for next loop + + System.out.println("Calculated result: "+result); + + } + } + catch(IOException e) + { + System.err.println("Problem with UdpReceiver, see exception trace:"); + System.err.println(e); + } + finally // clean up prior to exit, don't want to leave behind zombie socket + { + if (udpSocket != null) + udpSocket.close(); + System.out.println(UDPResultReceiver.class.getName() + " complete."); // all done + } + } + +} diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/logic.jpg b/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/logic.jpg new file mode 100644 index 0000000000000000000000000000000000000000..5fa827094c869ea38ad6d265395843694f0263b8 Binary files /dev/null and b/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/logic.jpg differ diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/logic.vsdx b/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/logic.vsdx new file mode 100644 index 0000000000000000000000000000000000000000..4d2e6878bd82a1d201bc8f4742ff1a67d4cc5f34 Binary files /dev/null and b/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/logic.vsdx differ diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/sequence.jpg b/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/sequence.jpg new file mode 100644 index 0000000000000000000000000000000000000000..44faf01bb3a35a5d7072c8705529f2ef73deecd7 Binary files /dev/null and b/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/sequence.jpg differ diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/sequence.vsdx b/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/sequence.vsdx new file mode 100644 index 0000000000000000000000000000000000000000..c43b2fe02d509af09eead57cd0180a2e5d5f1567 Binary files /dev/null and b/assignments/src/MV3500Cohort2020JulySeptember/homework3/WeissenbergerGoericke/sequence.vsdx differ diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/White/UdpReceiver.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/White/UdpReceiver.java new file mode 100644 index 0000000000000000000000000000000000000000..3038d6c38f4dd72197269901ef2ba8e65fef339f --- /dev/null +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/White/UdpReceiver.java @@ -0,0 +1,92 @@ +package MV3500Cohort2020JulySeptember.homework3.White; + +import java.io.*; +import java.net.*; + +/** + * An example of receiving UDP packets. Since very often both the + * sender and receiver are on the same host we use different ports + * for each. This prevents collision complaints from the localhost. + * + * Start this before launching UdpSender. + * + * @see https://docs.oracle.com/javase/tutorial/essential/io/datastreams.html + * @see https://en.wikipedia.org/wiki/User_Datagram_Protocol + * @author mcgredo + * @author brutzman + */ +public class UdpReceiver +{ +// public static final int SENDING_PORT = 1414; // port used by UdpSender, unneeded here + public static final int RECEIVING_PORT = 1415; + public static final String DESINATION_HOST = "localhost"; + + /** + * @param args the command line arguments + * @throws java.io.IOException + */ + public static void main(String[] args) throws IOException + { + DatagramSocket udpSocket = null; + + try + { + System.out.println(UdpReceiver.class.getName() + " started..."); + + // Create a UDP socket + udpSocket = new DatagramSocket(RECEIVING_PORT); + udpSocket.setReceiveBufferSize(1500); // how many bytes are in buffer? MTU=1500 is good + udpSocket.setBroadcast(false); // we're just receiving here + + byte[] byteArray = new byte[1500]; + DatagramPacket receivePacket = new DatagramPacket(byteArray, byteArray.length); + + ByteArrayInputStream bais = new ByteArrayInputStream(byteArray); + DataInputStream dis = new DataInputStream(bais); + + boolean isEvenParity; + int packetCount = 0; + int firstInt; + float secondFloat; + String thirdString; + String padding; + + // You need a new receiving packet to read from every packet received + while (true) + { + packetCount++; // good practice to increment counter at start of loop, when possible + udpSocket.receive(receivePacket); // blocks until packet is received + + // values of interest follow. order and types of what was sent must match what you are reading! + firstInt = dis.readInt(); // packetID + secondFloat = dis.readFloat(); + thirdString = dis.readUTF(); // string value with guaranteed encoding, matches UTF-8 is 8 bit + isEvenParity = dis.readBoolean(); // ok, we've gotten everything we're looking for. + + dis.reset(); // now clear the input stream after reading, in preparation for next loop + + if (isEvenParity) + padding = " "; + else padding = ""; + + System.out.println("[" + UdpReceiver.class.getName() + "]" + + " packetID=" + firstInt + // have output message use same name as sender + ", second float value=" + secondFloat + + ", third String value=\"" + thirdString + "\"" + // note that /" is literal quote character + " isPacketIdEvenParity=" + isEvenParity + "," + padding + + " packet counter=" + packetCount); + } + } + catch(IOException e) + { + System.err.println("Problem with UdpReceiver, see exception trace:"); + System.err.println(e); + } + finally // clean up prior to exit, don't want to leave behind zombie socket + { + if (udpSocket != null) + udpSocket.close(); + System.out.println(UdpReceiver.class.getName() + " complete."); // all done + } + } +} diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/White/UdpRecieverLog.md b/assignments/src/MV3500Cohort2020JulySeptember/homework3/White/UdpRecieverLog.md new file mode 100644 index 0000000000000000000000000000000000000000..e7ebae81c9dc96f47e8fd850af64785deb81303b --- /dev/null +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/White/UdpRecieverLog.md @@ -0,0 +1,88 @@ +ant -f C:\\Users\\ctsfi\\Documents\\NetBeansProjects\\MV3500\\NetworkedGraphicsMV3500\\assignments -Dnb.internal.action.name=run.single -Djavac.includes=MV3500Cohort2020JulySeptember/homework3/White/UdpReceiver.java -Drun.class=MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver run-single +init: +Deleting: C:\Users\ctsfi\Documents\NetBeansProjects\MV3500\NetworkedGraphicsMV3500\assignments\build\built-jar.properties +deps-jar: +Updating property file: C:\Users\ctsfi\Documents\NetBeansProjects\MV3500\NetworkedGraphicsMV3500\assignments\build\built-jar.properties +Compiling 1 source file to C:\Users\ctsfi\Documents\NetBeansProjects\MV3500\NetworkedGraphicsMV3500\assignments\build\classes +warning: [options] bootstrap class path not set in conjunction with -source 8 +1 warning +compile-single: +run-single: +MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver started... +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=1, second float value=9999.0, third String value="42 is the answer" isPacketIdEvenParity=false, packet counter=1 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=2, second float value=9998.0, third String value="42 is the answer" isPacketIdEvenParity=true, packet counter=2 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=3, second float value=9997.0, third String value="42 is the answer" isPacketIdEvenParity=false, packet counter=3 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=4, second float value=9996.0, third String value="42 is the answer" isPacketIdEvenParity=true, packet counter=4 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=5, second float value=9995.0, third String value="42 is the answer" isPacketIdEvenParity=false, packet counter=5 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=6, second float value=9994.0, third String value="42 is the answer" isPacketIdEvenParity=true, packet counter=6 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=7, second float value=9993.0, third String value="42 is the answer" isPacketIdEvenParity=false, packet counter=7 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=8, second float value=9992.0, third String value="42 is the answer" isPacketIdEvenParity=true, packet counter=8 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=9, second float value=9991.0, third String value="42 is the answer" isPacketIdEvenParity=false, packet counter=9 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=10, second float value=9990.0, third String value="42 is the answer" isPacketIdEvenParity=true, packet counter=10 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=11, second float value=9989.0, third String value="42 is the answer" isPacketIdEvenParity=false, packet counter=11 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=12, second float value=9988.0, third String value="42 is the answer" isPacketIdEvenParity=true, packet counter=12 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=13, second float value=9987.0, third String value="42 is the answer" isPacketIdEvenParity=false, packet counter=13 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=14, second float value=9986.0, third String value="42 is the answer" isPacketIdEvenParity=true, packet counter=14 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=15, second float value=9985.0, third String value="42 is the answer" isPacketIdEvenParity=false, packet counter=15 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=16, second float value=9984.0, third String value="42 is the answer" isPacketIdEvenParity=true, packet counter=16 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=1, second float value=99.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=false, packet counter=17 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=17, second float value=9983.0, third String value="42 is the answer" isPacketIdEvenParity=false, packet counter=18 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=2, second float value=98.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=true, packet counter=19 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=18, second float value=9982.0, third String value="42 is the answer" isPacketIdEvenParity=true, packet counter=20 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=3, second float value=97.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=false, packet counter=21 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=19, second float value=9981.0, third String value="42 is the answer" isPacketIdEvenParity=false, packet counter=22 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=4, second float value=96.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=true, packet counter=23 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=20, second float value=9980.0, third String value="42 is the answer" isPacketIdEvenParity=true, packet counter=24 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=5, second float value=95.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=false, packet counter=25 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=21, second float value=9979.0, third String value="42 is the answer" isPacketIdEvenParity=false, packet counter=26 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=6, second float value=94.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=true, packet counter=27 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=22, second float value=9978.0, third String value="42 is the answer" isPacketIdEvenParity=true, packet counter=28 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=7, second float value=93.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=false, packet counter=29 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=23, second float value=9977.0, third String value="42 is the answer" isPacketIdEvenParity=false, packet counter=30 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=8, second float value=92.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=true, packet counter=31 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=24, second float value=9976.0, third String value="42 is the answer" isPacketIdEvenParity=true, packet counter=32 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=9, second float value=91.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=false, packet counter=33 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=25, second float value=9975.0, third String value="42 is the answer" isPacketIdEvenParity=false, packet counter=34 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=10, second float value=90.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=true, packet counter=35 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=26, second float value=9974.0, third String value="42 is the answer" isPacketIdEvenParity=true, packet counter=36 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=11, second float value=89.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=false, packet counter=37 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=27, second float value=9973.0, third String value="42 is the answer" isPacketIdEvenParity=false, packet counter=38 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=12, second float value=88.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=true, packet counter=39 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=28, second float value=9972.0, third String value="42 is the answer" isPacketIdEvenParity=true, packet counter=40 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=13, second float value=87.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=false, packet counter=41 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=29, second float value=9971.0, third String value="42 is the answer" isPacketIdEvenParity=false, packet counter=42 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=14, second float value=86.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=true, packet counter=43 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=30, second float value=9970.0, third String value="42 is the answer" isPacketIdEvenParity=true, packet counter=44 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=15, second float value=85.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=false, packet counter=45 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=31, second float value=9969.0, third String value="42 is the answer" isPacketIdEvenParity=false, packet counter=46 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=16, second float value=84.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=true, packet counter=47 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=32, second float value=9968.0, third String value="42 is the answer" isPacketIdEvenParity=true, packet counter=48 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=17, second float value=83.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=false, packet counter=49 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=33, second float value=9967.0, third String value="42 is the answer" isPacketIdEvenParity=false, packet counter=50 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=18, second float value=82.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=true, packet counter=51 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=34, second float value=9966.0, third String value="42 is the answer" isPacketIdEvenParity=true, packet counter=52 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=19, second float value=81.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=false, packet counter=53 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=35, second float value=9965.0, third String value="42 is the answer" isPacketIdEvenParity=false, packet counter=54 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=20, second float value=80.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=true, packet counter=55 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=36, second float value=9964.0, third String value="42 is the answer" isPacketIdEvenParity=true, packet counter=56 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=21, second float value=79.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=false, packet counter=57 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=1, second float value=99.0, third String value="We got London on da Track" isPacketIdEvenParity=false, packet counter=58 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=37, second float value=9963.0, third String value="42 is the answer" isPacketIdEvenParity=false, packet counter=59 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=22, second float value=78.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=true, packet counter=60 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=2, second float value=98.0, third String value="We got London on da Track" isPacketIdEvenParity=true, packet counter=61 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=38, second float value=9962.0, third String value="42 is the answer" isPacketIdEvenParity=true, packet counter=62 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=23, second float value=77.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=false, packet counter=63 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=3, second float value=97.0, third String value="We got London on da Track" isPacketIdEvenParity=false, packet counter=64 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=39, second float value=9961.0, third String value="42 is the answer" isPacketIdEvenParity=false, packet counter=65 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=24, second float value=76.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=true, packet counter=66 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=4, second float value=96.0, third String value="We got London on da Track" isPacketIdEvenParity=true, packet counter=67 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=40, second float value=9960.0, third String value="42 is the answer" isPacketIdEvenParity=true, packet counter=68 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=25, second float value=75.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=false, packet counter=69 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=5, second float value=95.0, third String value="We got London on da Track" isPacketIdEvenParity=false, packet counter=70 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=41, second float value=9959.0, third String value="42 is the answer" isPacketIdEvenParity=false, packet counter=71 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=26, second float value=74.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=true, packet counter=72 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=6, second float value=94.0, third String value="We got London on da Track" isPacketIdEvenParity=true, packet counter=73 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=42, second float value=9958.0, third String value="42 is the answer" isPacketIdEvenParity=true, packet counter=74 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=27, second float value=73.0, third String value="chris says we need to understand llamas in order to code" isPacketIdEvenParity=false, packet counter=75 +[MV3500Cohort2020JulySeptember.homework3.White.UdpReceiver] packetID=7, second float value=93.0, third String value="We got London on da Track" isPacketIdEvenParity=false, packet counter=76 +BUILD STOPPED (total time: 59 seconds) diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/White/UdpSender.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/White/UdpSender.java new file mode 100644 index 0000000000000000000000000000000000000000..d22d843330bf01b15fe4fd6edacbfea592ececc6 --- /dev/null +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/White/UdpSender.java @@ -0,0 +1,115 @@ +package MV3500Cohort2020JulySeptember.homework3.White; + +import java.io.*; +import java.net.*; + +/** + * An example of sending UDP packets. The sending and receiving programs + * use different UDP ports; there can be problems getting this to work + * if both the sending and receiving sockets try to use the same port + * on the same host. + * + * Start this before launching UdpReceiver. + * + * @see https://docs.oracle.com/javase/tutorial/essential/io/datastreams.html + * @see https://en.wikipedia.org/wiki/User_Datagram_Protocol + * @author mcgredo + * @author brutzman + */ +public class UdpSender +{ + // System properties: https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html + public static final String MY_NAME = "Alex"; // guru incantation 8) +// public static final int SENDING_PORT = 1414; // not needed, can let system choose an open local port + public static final int RECEIVING_PORT = 1415; + public static final int TOTAL_PACKETS_TO_SEND = 100; + + // here is what we need for lab comms + public static final String DESTINATION_HOST = "10.1.105.8"; // localhost 127.0.0.1 or argon 10.1.105.1 or 10.1.105.1 or whatever + + @SuppressWarnings("SleepWhileInLoop") + public static void main(String[] args) throws IOException + { + DatagramSocket udpSocket = null; + DataOutputStream dos = null; + int packetID = 0; // counter variable to send in packet + float value = -1.0f; // unreachable value is good sentinel to ensure expected changes occur + String message = MY_NAME + " says Fuck You, Pay Me"; // no really + String padding = new String(); + + try + { + System.out.println(UdpSender.class.getName() + " shows how to send simple-type values via DataOutputStream"); + System.out.println(UdpSender.class.getName() + " started..."); + + // Create a UDP socket + udpSocket = new DatagramSocket(); // let system assign output port, then SENDING_PORT not needed + + // Put together a message with binary content. "ByteArrayOutputStream" + // is a java.io utility that lets us put together an array of binary + // data, which we put into the UDP packet. + + ByteArrayOutputStream baos = new ByteArrayOutputStream(1500); // how many bytes are in buffer? MTU=1500 is good + dos = new DataOutputStream(baos); // wrapper for writing values, connects both streams + + // Put together a packet to send + // these types and order of variables must match on sender and receiver + byte[] byteArray = baos.toByteArray(); + + // ID of the host we are sending to + InetAddress destinationAddress = InetAddress.getByName(DESTINATION_HOST); + // ID of the host we are sending from + InetAddress sourceAddress = InetAddress.getByName("localhost"); // possibly identical if source not modified + + DatagramPacket datagramPacket = new DatagramPacket(byteArray, byteArray.length, destinationAddress, RECEIVING_PORT); + + // Hmmm, how fast does UDP stream go? Does UDP effectively slow packets down, or does + // this cause network problems? (hint: yes for an unlimited send rate, unlike TCP). + // How do you know on the receiving side that you haven't received a + // duplicate UDP packet, out-of-order packet, or dropped packet? your responsibility. + + for (int index = 1; index <= TOTAL_PACKETS_TO_SEND; index++) // avoid infinite send loops in code, they can be hard to kill! + { + packetID++; // increment counter, prefer using explicit value to index + value = TOTAL_PACKETS_TO_SEND - packetID; // countdown + boolean isPacketIdEvenParity = ((packetID % 2) == 0); // % is modulo operator; result 0 is even parity, 1 is odd parity + + // values of interest follow. order and types of what was sent must match what you are reading! + dos.writeInt (packetID); + dos.writeFloat (value); + dos.writeUTF (message); // string value with guaranteed encoding, matches UTF-8 is 8 bit + dos.writeBoolean(isPacketIdEvenParity); + + dos.flush(); // sends DataOutputStream to ByteArrayOutputStream + byteArray = baos.toByteArray(); // OK so go get the flushed result... + datagramPacket.setData(byteArray); // and put it in the packet... + udpSocket.send(datagramPacket); // and send it away. boom gone, nonblocking. +// System.out.println("udpSocket output port=" + udpSocket.getLocalPort()); // diagnostic tells what port was chosen by system + + if (isPacketIdEvenParity) + padding = " "; + else padding = ""; + + Thread.sleep(1000); // Send packets at rate of one per second + System.out.println("[" + UdpSender.class.getName() + "] " + MY_NAME + " " + sourceAddress + + " sent values(" + packetID + "," + value + ",\"" + message + "\"," + isPacketIdEvenParity + + ")" + padding + " as packet #" + index + " of " + TOTAL_PACKETS_TO_SEND); + baos.reset(); // clear the output stream after sending + } + } + catch (IOException | InterruptedException e) + { + System.err.println("Problem with UdpSender, see exception trace:"); + System.err.println(e); + } + finally // clean up prior to exit, don't want to leave behind zombies + { + if (udpSocket != null) + udpSocket.close(); + + if (dos != null) + dos.close(); + System.out.println(UdpSender.class.getName() + " complete."); // all done + } + } +} diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework4/WeissenbergerGoericke/.gitkeep b/assignments/src/MV3500Cohort2020JulySeptember/homework4/WeissenbergerGoericke/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework4/WeissenbergerGoericke/ProjectIdeaTeamGermany.jpg b/assignments/src/MV3500Cohort2020JulySeptember/homework4/WeissenbergerGoericke/ProjectIdeaTeamGermany.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2a9ac8e61fabb4a80973264378387b23cd334733 Binary files /dev/null and b/assignments/src/MV3500Cohort2020JulySeptember/homework4/WeissenbergerGoericke/ProjectIdeaTeamGermany.jpg differ diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework4/WeissenbergerGoericke/README.md b/assignments/src/MV3500Cohort2020JulySeptember/homework4/WeissenbergerGoericke/README.md new file mode 100644 index 0000000000000000000000000000000000000000..0144d62d033fbe094ceac7a6d1bedc12d3c158b0 --- /dev/null +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework4/WeissenbergerGoericke/README.md @@ -0,0 +1,12 @@ +## Homework 2: Multicast Networking + +Modify this file to describe your project work. + +Typical deliverables include properly packages source, execution log, and screen shots as appropriate. + +References include +* [README.md](../README.md) for this homework project. +* [README.md](../../../../README.md) for course assignments execution instructions. +* [assignments source subdirectories](../../../../../assignments/src) show examples from previous cohorts. + +Questions and innovation are always welcome, good luck! diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework4/WeissenbergerGoericke/TCPReceiverVPNBridge.java b/assignments/src/MV3500Cohort2020JulySeptember/homework4/WeissenbergerGoericke/TCPReceiverVPNBridge.java new file mode 100644 index 0000000000000000000000000000000000000000..43a014be20109e9c245bb84136253d0995e10c67 --- /dev/null +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework4/WeissenbergerGoericke/TCPReceiverVPNBridge.java @@ -0,0 +1,99 @@ + +package MV3500Cohort2020JulySeptember.homework4.Weissenberger; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; + +/** + * Just for me for testing - not part of Homework #3! + * @author Loki + */ +public class TCPReceiverVPNBridge { + + protected static String server_IP_VPN = "10.1.105.9"; // argon IP + protected static String server_IP_Local = "192.168.188.103"; // Local IP + + private static final int server_Port = 2317 ; + protected static String client_IP ; + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + 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("TcpExample3Server has started..."); // it helps debugging to put this on console first + + ServerSocket serverSocket = new ServerSocket(server_Port); + 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); + ps.println("This is response " + serverLoopCount + " produced by the server."); // this gets sent back to client! + + // 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("TcpExample3Server 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"); + + // Notice 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 TcpExample3Server 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/MV3500Cohort2020JulySeptember/homework4/WeissenbergerGoericke/TcpServerForFinal.java b/assignments/src/MV3500Cohort2020JulySeptember/homework4/WeissenbergerGoericke/TcpServerForFinal.java new file mode 100644 index 0000000000000000000000000000000000000000..5e7066c139149084e89bd0cae45237e550476ddf --- /dev/null +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework4/WeissenbergerGoericke/TcpServerForFinal.java @@ -0,0 +1,91 @@ +package MV3500Cohort2020JulySeptember.homework4.Weissenberger; + +import java.io.*; +import java.net.*; + +/** + * Very slightly more complex than example1, further modifying example2. The + * only thing this does differently is introduce a loop into the response, so + * you don't have to restart the program after one response. Also, it prints out + * the socket pair the server sees. Run the program via telnet several times and + * compare the socket pairs. + * + * telnet (nc) localhost 2317 + * + * If you're sophisticated you can contact the instructor's computer while + * running this program. + * + * telnet (nc) [ipNumberOfServerLaptop] 2317 + * + * and have the instructor display the socket pairs received. + * + * @author mcgredo + * @author brutzman + */ +public class TcpServerForFinal { + + public static void main(String[] args) { + 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("TcpExample3Server has started..."); // it helps debugging to put this on console first + + //ServerSocket serverSocket = new ServerSocket(2317); + InetAddress[] ia = InetAddress.getAllByName("192.168.188.106"); + for (int i = 0;i < ia.length; i++){ + System.out.println("---: "+ia[i]); + } + ServerSocket serverSocket = new ServerSocket(2317, 100, ia[0]); + + InputStream is; + InputStreamReader isr; + BufferedReader br; + String serverMessage; + + + 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) { + System.out.println("Look for connection...."); + // 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: + is = clientConnectionSocket.getInputStream(); + isr = new InputStreamReader(is); + br = new BufferedReader(isr); + + serverMessage = br.readLine(); + System.out.println("The message the mobile sent was: '" + serverMessage + "'"); + // 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.println ("Server loop " + serverLoopCount + ": "); + + System.out.println("TcpExample3Server socket pair showing host name, address, port:"); + + } + } + } catch (IOException e) { + System.err.println("Problem with TcpExample3Server 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/documentation/Wireshark/README.md b/documentation/Wireshark/README.md new file mode 100644 index 0000000000000000000000000000000000000000..4ce32c0fd9eac8b80598ef60934534c18bcbe23c --- /dev/null +++ b/documentation/Wireshark/README.md @@ -0,0 +1,63 @@ +# Wireshark Setup and Usage <a href="https://www.wireshark.org"><img src="images/wireshark_logo.png" align="right"/></a> + +> Wireshark is the world’s foremost and widely-used network protocol analyzer. +> It lets you see what’s happening on your network at a microscopic level and +> is the de facto (and often de jure) standard across many commercial and non-profit enterprises, +> government agencies, and educational institutions. +> Wireshark development thrives thanks to the volunteer contributions of networking experts +> around the globe and is the continuation of a project started by Gerald Combs in 1998. + +[Wireshark](https://www.wireshark.org) is an excellent open-source tool with wide use. +Capabilities include inspection of <code>dis</code> packets. + +[Capturing DIS Packets](Capturing_DIS_Packets.pdf) by Tobias Brennenstuhl is his +[thesis annex](https://calhoun.nps.edu/handle/10945/65436) +specifically written to help support student efforts. + +## Installation and Configuration + +IMPORTANT: if you have already installed Wireshark, check your version! +Always use the latest so that operating-system security and feature sets are up to date. + +1. Download Wireshark from https://www.wireshark.org +2. Install as local administrator if possible +3. Launch and see if network packets are being detected. + +| Successful installation, monitoring | Failed installation, no monitoring | +| ------ | ------ | +| <a href="images/WiresharkNetworkInterfaces.png"><img src="images/WiresharkNetworkInterfaces.png" width="400" align="center"/></a> | <a href="images/WiresharkNoNetworkTraffic.png"><img src="images/WiresharkNoNetworkTraffic.png" width="400" align="center"/></a> | + +4. Check your network interfaces via console commands [ipconfig](ipconfig.txt) +5. Double-check network interfaces using [ipconfig /all](ipconfigAllExcerpt.txt) to see any hidden interfaces + +## Capturing Packets + +1. Confirm preferences: File > Preferences > Capture as shown + +<a href="images/WiresharkCapturePreferences.png"><img src="images/WiresharkCapturePreferences.png" width="400" align="center"/> + +2. Set filter to dis +3. Lauch one of the example programs to send packets, then observe results. + +<a href="images/WiresharkUdpDisPduCapture.png"><img src="images/WiresharkUdpDisPduCapture.png" width="400" align="center"/> + +## Troubleshooting + +1. Check your [firewall settings](Firewall_Configuration.pdf). (Again thanks to Tobias for another helpful reference.) +2. Compare Wireshark results with/without your [Virtual Private Network (VPN)](https://en.wikipedia.org/wiki/Virtual_private_network) active. +3. Compare Wireshark results when logged in as local administrator, if possible. +4. [StackOverflow](https://stackoverflow.com/search?q=wireshark) is an excellent resource for detailed technical questions, looking up error messages, etc. + +## Videos + +1. [Intro to Wireshark: Basics + Packet Analysis!](https://www.youtube.com/watch?v=TkCSr30UojM) by SinnohStarly - Ross Teixeira. +2. [Wireshark Tutorial for Beginners](https://www.youtube.com/watch?v=TkCSr30UojM) by Anson Alexander +3. [Back to Basics](https://www.youtube.com/watch?v=y13zH-8OPE8&t=9s) video by Hansang Bae. "Read.... READ I SAY!!!!" + +## References + +1. [Wireshark home page](https://www.wireshark.org) and [Learning Wireshark](https://www.wireshark.org/#learnWS) +2. [Wireshark User’s Guide](https://www.wireshark.org/docs/wsug_html_chunked) +3. [Wireshark Frequently Asked Questions (FAQ)](https://www.wireshark.org/faq.html) and [Ask Wireshark](https://ask.wireshark.org/questions) +4. [NPS Remote Access and Wireless Services](https://nps.edu/web/technology/remote-access) +5. Tobias Brennenstuhl, [REPEATABLE UNIT TESTING OF DISTRIBUTED INTERACTIVE SIMULATION (DIS) PROTOCOL BEHAVIOR STREAMS USING WEB STANDARDS](https://calhoun.nps.edu/handle/10945/65436), MOVES Masters Thesis, Naval Postgraduate School (NPS), Monterey California USA, June 2020. diff --git a/documentation/Wireshark/images/WiresharkCapturePreferences.png b/documentation/Wireshark/images/WiresharkCapturePreferences.png new file mode 100644 index 0000000000000000000000000000000000000000..9258ed18c6d7385b3418bd88195aeebe88d5be64 Binary files /dev/null and b/documentation/Wireshark/images/WiresharkCapturePreferences.png differ diff --git a/documentation/Wireshark/images/WiresharkNetworkInterfaces.png b/documentation/Wireshark/images/WiresharkNetworkInterfaces.png new file mode 100644 index 0000000000000000000000000000000000000000..61a3667521725777ab4185dd5e1dbf0af08dd0de Binary files /dev/null and b/documentation/Wireshark/images/WiresharkNetworkInterfaces.png differ diff --git a/documentation/Wireshark/images/WiresharkNoNetworkTraffic.png b/documentation/Wireshark/images/WiresharkNoNetworkTraffic.png new file mode 100644 index 0000000000000000000000000000000000000000..8ab66283adbb30d793d1104f79286e1f5c37ccf5 Binary files /dev/null and b/documentation/Wireshark/images/WiresharkNoNetworkTraffic.png differ diff --git a/documentation/Wireshark/images/WiresharkUdpDisPduCapture.png b/documentation/Wireshark/images/WiresharkUdpDisPduCapture.png new file mode 100644 index 0000000000000000000000000000000000000000..848707358b6dca6d7d14088670e94aa32655af2d Binary files /dev/null and b/documentation/Wireshark/images/WiresharkUdpDisPduCapture.png differ diff --git a/documentation/Wireshark/images/wireshark_logo.png b/documentation/Wireshark/images/wireshark_logo.png new file mode 100644 index 0000000000000000000000000000000000000000..b9df5762f595d77a5613b945e3cfdeade5782d70 Binary files /dev/null and b/documentation/Wireshark/images/wireshark_logo.png differ diff --git a/documentation/Wireshark/ipconfig.txt b/documentation/Wireshark/ipconfig.txt new file mode 100644 index 0000000000000000000000000000000000000000..29a00b1a839afb993a983dcda6aed39411aa9353 --- /dev/null +++ b/documentation/Wireshark/ipconfig.txt @@ -0,0 +1,33 @@ +Example "ipconfig" output: + +Windows IP Configuration + +Ethernet adapter Ethernet 7: + + Connection-specific DNS Suffix . : + IPv4 Address. . . . . . . . . . . : 172.20.223.70 + Subnet Mask . . . . . . . . . . . : 255.255.255.255 + Default Gateway . . . . . . . . . : 0.0.0.0 + +Ethernet adapter Ethernet: + + Media State . . . . . . . . . . . : Media disconnected + Connection-specific DNS Suffix . : ern.nps.edu + +Wireless LAN adapter Local Area Connection* 4: + + Media State . . . . . . . . . . . : Media disconnected + Connection-specific DNS Suffix . : + +Wireless LAN adapter Wi-Fi: + + Connection-specific DNS Suffix . : + Link-local IPv6 Address . . . . . : fe80::6c31:f4d3:2fc3:8b37%17 + IPv4 Address. . . . . . . . . . . : 10.0.0.9 + Subnet Mask . . . . . . . . . . . : 255.255.255.0 + Default Gateway . . . . . . . . . : 10.0.0.1 + +Ethernet adapter Bluetooth Network Connection: + + Media State . . . . . . . . . . . : Media disconnected + Connection-specific DNS Suffix . : diff --git a/documentation/Wireshark/ipconfigAllExcerpt.txt b/documentation/Wireshark/ipconfigAllExcerpt.txt new file mode 100644 index 0000000000000000000000000000000000000000..d1857033741d1ee64af49fc382017ecb66c55bea --- /dev/null +++ b/documentation/Wireshark/ipconfigAllExcerpt.txt @@ -0,0 +1,16 @@ +Here is "ipconfig /all" excerpt, which did not appear before: + +Ethernet adapter Ethernet 7: + Connection-specific DNS Suffix . : + Description . . . . . . . . . . . : PANGP Virtual Ethernet Adapter #5 + Physical Address. . . . . . . . . : 02-50-41-00-00-01 + DHCP Enabled. . . . . . . . . . . : No + Autoconfiguration Enabled . . . . : Yes + IPv4 Address. . . . . . . . . . . : 172.20.223.70(Preferred) + Subnet Mask . . . . . . . . . . . : 255.255.255.255 + Default Gateway . . . . . . . . . : 0.0.0.0 + DHCPv6 IAID . . . . . . . . . . . : 553799745 + DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-20-AF-7B-22-D4-81-D7-C4-72-74 + DNS Servers . . . . . . . . . . . : 172.20.20.11 + 172.20.20.12 + NetBIOS over Tcpip. . . . . . . . : Enabled diff --git a/documentation/images/OpenDisSurferDude.png b/documentation/images/OpenDisSurferDude.png new file mode 100644 index 0000000000000000000000000000000000000000..f9e558c33c4af10580a9faaef260c18325715903 Binary files /dev/null and b/documentation/images/OpenDisSurferDude.png differ diff --git a/examples/src/HttpServletExamples/JavaServletArchitecture.pdf b/examples/src/HttpServletExamples/JavaServletArchitecture.pdf new file mode 100644 index 0000000000000000000000000000000000000000..b4471ff80a3cb8f629f2181894c5d8ea46f07aec Binary files /dev/null and b/examples/src/HttpServletExamples/JavaServletArchitecture.pdf differ diff --git a/examples/src/HttpServletExamples/JavaServletArchitecture.png b/examples/src/HttpServletExamples/JavaServletArchitecture.png new file mode 100644 index 0000000000000000000000000000000000000000..b0b336460bdcf2e0a7bebf6e3d07f570034f19f8 Binary files /dev/null and b/examples/src/HttpServletExamples/JavaServletArchitecture.png differ diff --git a/examples/src/HttpServletExamples/JavaServletArchitecture.vsdx b/examples/src/HttpServletExamples/JavaServletArchitecture.vsdx new file mode 100644 index 0000000000000000000000000000000000000000..5492753a1ceaf505e0d7837434ff9ff0011a8324 Binary files /dev/null and b/examples/src/HttpServletExamples/JavaServletArchitecture.vsdx differ diff --git a/examples/src/OpenDis7Examples/ExampleSimulationProgramOutput.txt b/examples/src/OpenDis7Examples/ExampleSimulationProgramOutput.txt new file mode 100644 index 0000000000000000000000000000000000000000..c0c67435b7d57df71569f9f11553d57f05f5b945 --- /dev/null +++ b/examples/src/OpenDis7Examples/ExampleSimulationProgramOutput.txt @@ -0,0 +1,71 @@ +ant -f C:\\x-nps-gitlab\\NetworkedGraphicsMV3500\\examples -Dnb.internal.action.name=run.single -Djavac.includes=OpenDis7Examples/ExampleSimulationProgram.java -Drun.class=OpenDis7Examples.ExampleSimulationProgram run-single +init: +Deleting: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\built-jar.properties +deps-jar: +Updating property file: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\built-jar.properties +Compiling 1 source file to C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\classes +warning: [options] bootstrap class path not set in conjunction with -source 8 +1 warning +compile-single: +run-single: +[edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface] Using network interface Intel(R) Dual Band Wireless-AC 8260 +Network confirmation: address=239.1.2.3 port=3000 +sending PDUs for simulation step 1, monitor loopback to confirm sent +[edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface] 1. received DISPDUType 1 ENTITY_STATE (timestamp 14:23:57, size 144 bytes) +[edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface] 2. received DISPDUType 2 FIRE (timestamp 14:24:01, size 96 bytes) +[edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface] 3. received DISPDUType 22 COMMENT (timestamp 14:28:02, size 96 bytes) +... PDUs successfully sent +sending PDUs for simulation step 2, monitor loopback to confirm sent +[edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface] 4. received DISPDUType 1 ENTITY_STATE (timestamp 14:23:57, size 144 bytes) +[edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface] 5. received DISPDUType 2 FIRE (timestamp 14:24:01, size 96 bytes) +[edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface] 6. received DISPDUType 22 COMMENT (timestamp 14:34:06, size 96 bytes) +... PDUs successfully sent +sending PDUs for simulation step 3, monitor loopback to confirm sent +[edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface] 7. received DISPDUType 1 ENTITY_STATE (timestamp 14:23:57, size 144 bytes) +[edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface] 8. received DISPDUType 2 FIRE (timestamp 14:24:01, size 96 bytes) +[edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface] 9. received DISPDUType 22 COMMENT (timestamp 14:40:06, size 96 bytes) +... PDUs successfully sent +sending PDUs for simulation step 4, monitor loopback to confirm sent +[edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface] 10. received DISPDUType 1 ENTITY_STATE (timestamp 14:23:57, size 144 bytes) +[edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface] 11. received DISPDUType 2 FIRE (timestamp 14:24:01, size 96 bytes) +[edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface] 12. received DISPDUType 22 COMMENT (timestamp 14:46:06, size 96 bytes) +... PDUs successfully sent +*** termination condition met, simulationComplete=true +BUILD SUCCESSFUL (total time: 3 seconds) + +====================================== +Example output log from AllPduReceiver: + +ant -f C:\\x-nps-gitlab\\NetworkedGraphicsMV3500\\examples -Dnb.internal.action.name=run.single -Djavac.includes=OpenDis7Examples/AllPduReceiver.java -Drun.class=OpenDis7Examples.AllPduReceiver run-single +init: +Deleting: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\built-jar.properties +deps-jar: +Updating property file: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\built-jar.properties +Compiling 1 source file to C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\classes +warning: [options] bootstrap class path not set in conjunction with -source 8 +Note: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\src\OpenDis7Examples\AllPduReceiver.java uses or overrides a deprecated API. +Note: Recompile with -Xlint:deprecation for details. +Note: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\src\OpenDis7Examples\AllPduReceiver.java uses unchecked or unsafe operations. +Note: Recompile with -Xlint:unchecked for details. +1 warning +compile-single: +run-single: +OpenDis7Examples.AllPduReceiver started... +Usage: AllPduReceiver <multicast group> <port> +Default: AllPduReceiver 239.1.2.3 3000 +14:23:57 received DIS PDU DISPDUType 1 ENTITY_STATE (DISProtocolFamily 1 ENTITY_INFORMATION_INTERACTION) +14:24:01 received DIS PDU DISPDUType 2 FIRE (DISProtocolFamily 2 WARFARE) +14:28:02 received DIS PDU DISPDUType 22 COMMENT (DISProtocolFamily 5 SIMULATION_MANAGEMENT) + messages: "MV3500 ExampleSimulation" "runSimulation loop 1" +14:23:57 received DIS PDU DISPDUType 1 ENTITY_STATE (DISProtocolFamily 1 ENTITY_INFORMATION_INTERACTION) +14:24:01 received DIS PDU DISPDUType 2 FIRE (DISProtocolFamily 2 WARFARE) +14:34:06 received DIS PDU DISPDUType 22 COMMENT (DISProtocolFamily 5 SIMULATION_MANAGEMENT) + messages: "MV3500 ExampleSimulation" "runSimulation loop 2" +14:23:57 received DIS PDU DISPDUType 1 ENTITY_STATE (DISProtocolFamily 1 ENTITY_INFORMATION_INTERACTION) +14:24:01 received DIS PDU DISPDUType 2 FIRE (DISProtocolFamily 2 WARFARE) +14:40:06 received DIS PDU DISPDUType 22 COMMENT (DISProtocolFamily 5 SIMULATION_MANAGEMENT) + messages: "MV3500 ExampleSimulation" "runSimulation loop 3" +14:23:57 received DIS PDU DISPDUType 1 ENTITY_STATE (DISProtocolFamily 1 ENTITY_INFORMATION_INTERACTION) +14:24:01 received DIS PDU DISPDUType 2 FIRE (DISProtocolFamily 2 WARFARE) +14:46:06 received DIS PDU DISPDUType 22 COMMENT (DISProtocolFamily 5 SIMULATION_MANAGEMENT) + messages: "MV3500 ExampleSimulation" "runSimulation loop 4" diff --git a/lib/open-dis7-enumerations-classes.jar b/lib/open-dis7-enumerations-classes.jar new file mode 100644 index 0000000000000000000000000000000000000000..31530698b56fb4f3c082f53d586fa206fff23d52 Binary files /dev/null and b/lib/open-dis7-enumerations-classes.jar differ diff --git a/lib/open-dis7-enumerations-javadoc.jar b/lib/open-dis7-enumerations-javadoc.jar new file mode 100644 index 0000000000000000000000000000000000000000..62c10d5c86e54a6c1385ac58d1b3ea933d696497 Binary files /dev/null and b/lib/open-dis7-enumerations-javadoc.jar differ diff --git a/lib/open-dis7-enumerations-source.jar b/lib/open-dis7-enumerations-source.jar new file mode 100644 index 0000000000000000000000000000000000000000..312eefb8cb21e01b7d7203a2f47963c4d3a96964 Binary files /dev/null and b/lib/open-dis7-enumerations-source.jar differ diff --git a/lib/open-dis7-pdus-classes.jar b/lib/open-dis7-pdus-classes.jar new file mode 100644 index 0000000000000000000000000000000000000000..982cfa4432d04b9117c6b2e05082b6e4db54c284 Binary files /dev/null and b/lib/open-dis7-pdus-classes.jar differ diff --git a/lib/open-dis7-pdus-javadoc.jar b/lib/open-dis7-pdus-javadoc.jar new file mode 100644 index 0000000000000000000000000000000000000000..19cb9d3343353dfdf02b222b09b57d15a8cd6ff7 Binary files /dev/null and b/lib/open-dis7-pdus-javadoc.jar differ diff --git a/lib/open-dis7-pdus-source.jar b/lib/open-dis7-pdus-source.jar new file mode 100644 index 0000000000000000000000000000000000000000..7a969003b81a82756802b53614b63786a7a490e5 Binary files /dev/null and b/lib/open-dis7-pdus-source.jar differ diff --git a/nbproject/jdk.xml b/nbproject/jdk.xml new file mode 100644 index 0000000000000000000000000000000000000000..3d29141bdc5618925dfb987183238a1d3ee92bde --- /dev/null +++ b/nbproject/jdk.xml @@ -0,0 +1,157 @@ +<?xml version="1.0" encoding="UTF-8"?><project name="jdk" basedir="."> + + + <description> + Permits selection of a JDK to use when building and running project. + See: http://www.netbeans.org/issues/show_bug.cgi?id=64160 + </description> + + <target name="-jdk-pre-preinit"> + <condition property="nbjdk.active-or-nbjdk.home"> + <or> + <and> + <isset property="nbjdk.active"/> + <not> + <equals arg1="${nbjdk.active}" arg2="default_platform"/> + </not> + </and> + <and> + <isset property="nbjdk.home"/> + <not> + <isset property="nbjdk.home.defaulted"/> + </not> + </and> + </or> + </condition> + </target> + + <target xmlns:common="http://java.netbeans.org/freeform/jdk.xml" name="-jdk-preinit" depends="-jdk-pre-preinit" if="nbjdk.active-or-nbjdk.home"> + <macrodef name="property" uri="http://java.netbeans.org/freeform/jdk.xml"> + <attribute name="name"/> + <attribute name="value"/> + <sequential> + <property name="@{name}" value="${@{value}}"/> + </sequential> + </macrodef> + <common:property name="nbjdk.home" value="platforms.${nbjdk.active}.home"/> + <common:property name="nbjdk.javac.tmp" value="platforms.${nbjdk.active}.javac"/> + <condition property=".exe" value=".exe"> + <os family="windows"/> + </condition> + <property name=".exe" value=""/> + <condition property="nbjdk.javac" value="${nbjdk.home}/bin/javac${.exe}"> + <equals arg1="${nbjdk.javac.tmp}" arg2="$${platforms.${nbjdk.active}.javac}"/> + </condition> + <property name="nbjdk.javac" value="${nbjdk.javac.tmp}"/> + <common:property name="nbjdk.java.tmp" value="platforms.${nbjdk.active}.java"/> + <condition property="nbjdk.java" value="${nbjdk.home}/bin/java${.exe}"> + <equals arg1="${nbjdk.java.tmp}" arg2="$${platforms.${nbjdk.active}.java}"/> + </condition> + <property name="nbjdk.java" value="${nbjdk.java.tmp}"/> + <common:property name="nbjdk.javadoc.tmp" value="platforms.${nbjdk.active}.javadoc"/> + <condition property="nbjdk.javadoc" value="${nbjdk.home}/bin/javadoc${.exe}"> + <equals arg1="${nbjdk.javadoc.tmp}" arg2="$${platforms.${nbjdk.active}.javadoc}"/> + </condition> + <property name="nbjdk.javadoc" value="${nbjdk.javadoc.tmp}"/> + <common:property name="nbjdk.bootclasspath.tmp" value="platforms.${nbjdk.active}.bootclasspath"/> + <condition property="nbjdk.bootclasspath" value="${nbjdk.home}/jre/lib/rt.jar"> + <equals arg1="${nbjdk.bootclasspath.tmp}" arg2="$${platforms.${nbjdk.active}.bootclasspath}"/> + </condition> + <property name="nbjdk.bootclasspath" value="${nbjdk.bootclasspath.tmp}"/> + <condition property="nbjdk.valid"> + <and> + <available file="${nbjdk.home}" type="dir"/> + <available file="${nbjdk.javac}" type="file"/> + <available file="${nbjdk.java}" type="file"/> + <available file="${nbjdk.javadoc}" type="file"/> + + </and> + </condition> + <echo level="verbose">nbjdk.active=${nbjdk.active} nbjdk.home=${nbjdk.home} nbjdk.java=${nbjdk.java} nbjdk.javac=${nbjdk.javac} nbjdk.javadoc=${nbjdk.javadoc} nbjdk.bootclasspath=${nbjdk.bootclasspath} nbjdk.valid=${nbjdk.valid} have-jdk-1.4=${have-jdk-1.4} have-jdk-1.5=${have-jdk-1.5}</echo> + </target> + + <target name="-jdk-warn" depends="-jdk-preinit" if="nbjdk.active-or-nbjdk.home" unless="nbjdk.valid"> + <property name="jdkhome.presumed" location="${java.home}/.."/> + <echo level="warning">Warning: nbjdk.active=${nbjdk.active} or nbjdk.home=${nbjdk.home} is an invalid Java platform; ignoring and using ${jdkhome.presumed}</echo> + </target> + + <target name="-jdk-presetdef-basic" depends="-jdk-preinit" if="nbjdk.valid" unless="nbjdk.presetdef.basic.done"> + + + <macrodef name="javac-presetdef"> + <attribute name="javacval"/> + <sequential> + <presetdef name="javac"> + <javac fork="yes" executable="@{javacval}"/> + </presetdef> + </sequential> + </macrodef> + <javac-presetdef javacval="${nbjdk.javac}"/> + <macrodef name="java-presetdef"> + <attribute name="javaval"/> + <sequential> + <presetdef name="java"> + <java fork="yes" jvm="@{javaval}"/> + </presetdef> + </sequential> + </macrodef> + <java-presetdef javaval="${nbjdk.java}"/> + <macrodef name="javadoc-presetdef"> + <attribute name="javadocval"/> + <sequential> + <presetdef name="javadoc"> + <javadoc executable="@{javadocval}"/> + </presetdef> + </sequential> + </macrodef> + <javadoc-presetdef javadocval="${nbjdk.javadoc}"/> + <macrodef name="junit-presetdef"> + <attribute name="javaval"/> + <sequential> + <presetdef name="junit"> + <junit fork="yes" jvm="@{javaval}"/> + </presetdef> + </sequential> + </macrodef> + <junit-presetdef javaval="${nbjdk.java}"/> + <property name="nbjdk.presetdef.basic.done" value="true"/> + </target> + + <target name="-jdk-presetdef-nbjpdastart" depends="-jdk-preinit" if="nbjdk.valid" unless="nbjdk.presetdef.nbjpdastart.done"> + <macrodef name="nbjpdastart-presetdef"> + <attribute name="bootcpval"/> + <sequential> + <presetdef name="nbjpdastart"> + <nbjpdastart> + <bootclasspath> + <path path="@{bootcpval}"/> + </bootclasspath> + </nbjpdastart> + </presetdef> + </sequential> + </macrodef> + <nbjpdastart-presetdef bootcpval="${nbjdk.bootclasspath}"/> + <property name="nbjdk.presetdef.nbjpdastart.done" value="true"/> + </target> + + <target name="-jdk-default" unless="nbjdk.active-or-nbjdk.home"> + + <property name="java.home.parent" location="${java.home}/.."/> + <condition property="nbjdk.home" value="${java.home.parent}"> + <available file="${java.home.parent}/lib/tools.jar" type="file"/> + </condition> + <condition property="nbjdk.home" value="${java.home}"> + <available file="${java.home}/lib/tools.jar" type="file"/> + </condition> + + <condition property="nbjdk.home" value="/Library/Java/Home"> + <available file="/Library/Java/Home" type="dir"/> + </condition> + + <property name="nbjdk.home" location="${java.home.parent}"/> + <property name="nbjdk.home.defaulted" value="true"/> + </target> + + <target name="-jdk-init" depends="-jdk-preinit,-jdk-warn,-jdk-presetdef-basic,-jdk-default"/> + +</project> \ No newline at end of file diff --git a/nbproject/nbjdk.properties b/nbproject/nbjdk.properties new file mode 100644 index 0000000000000000000000000000000000000000..7fc8ad8110ca1630a2c14bc2c123b5acfe698517 --- /dev/null +++ b/nbproject/nbjdk.properties @@ -0,0 +1 @@ +nbjdk.active=Open_JDK_14.0.2 diff --git a/nbproject/nbjdk.xml b/nbproject/nbjdk.xml new file mode 100644 index 0000000000000000000000000000000000000000..22ced4d044b466209fa9187daaadc4dd58d600b5 --- /dev/null +++ b/nbproject/nbjdk.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project basedir=".." name="Networked_Graphics_MV3500"> + <property file="nbproject/nbjdk.properties"/> + <property location="${netbeans.user}/build.properties" name="user.properties.file"/> + <property file="${user.properties.file}"/> + <import file="jdk.xml"/> +</project>