diff --git a/MV3500NetworkedGraphicsSyllabus2020JulySeptember.doc b/MV3500NetworkedGraphicsSyllabus2020JulySeptember.doc index 27e0e253c57e04d805acacd87bdbd55df954beea..54c4806d71c9c5f8f485407f170f90bc7f359ada 100644 Binary files a/MV3500NetworkedGraphicsSyllabus2020JulySeptember.doc and b/MV3500NetworkedGraphicsSyllabus2020JulySeptember.doc differ diff --git a/MV3500NetworkedGraphicsSyllabus2020JulySeptember.pdf b/MV3500NetworkedGraphicsSyllabus2020JulySeptember.pdf index 7340176e02d5c73eed8343604672024da32f1c3b..e2483d7ab1d80d78e44e6b3b5f80748ced084bff 100644 Binary files a/MV3500NetworkedGraphicsSyllabus2020JulySeptember.pdf and b/MV3500NetworkedGraphicsSyllabus2020JulySeptember.pdf differ diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework2/Britt/Diagram.pdf b/assignments/src/MV3500Cohort2020JulySeptember/homework2/Britt/Diagram.pdf new file mode 100644 index 0000000000000000000000000000000000000000..331bc77de900b742dcb6baa3a71cf74653ca5d84 Binary files /dev/null and b/assignments/src/MV3500Cohort2020JulySeptember/homework2/Britt/Diagram.pdf differ diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework2/Weissenberger/LokiServerThread.java b/assignments/src/MV3500Cohort2020JulySeptember/homework2/Weissenberger/LokiServerThread.java index a8dfc011f097413cb779d4dd88927c7801f55da0..ad3238eaeb477600fca454267e2ebd9d28477179 100644 --- a/assignments/src/MV3500Cohort2020JulySeptember/homework2/Weissenberger/LokiServerThread.java +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework2/Weissenberger/LokiServerThread.java @@ -6,7 +6,7 @@ import java.net.*; /** * A program that handles all logic associated with one socket connection * by running in a thread of its own. This is the server - * portion + * portion (little changes) * * @author Bernd Weissenberger */ diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Garibay/UDPReceiverGaribay.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Garibay/UDPReceiverGaribay.java new file mode 100644 index 0000000000000000000000000000000000000000..2f1b250b8d9b45e30625ddfc4de3c28441861ba4 --- /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(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/Garibay/UDPSenderGaribay.java b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Garibay/UDPSenderGaribay.java new file mode 100644 index 0000000000000000000000000000000000000000..21c6de803955c64d7ea0a8d431185b524e839733 --- /dev/null +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Garibay/UDPSenderGaribay.java @@ -0,0 +1,114 @@ + +package MV3500Cohort2020JulySeptember.homework3.Garibay; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +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(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/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/README.md b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/README.md index 0144d62d033fbe094ceac7a6d1bedc12d3c158b0..3ec21e2b976a5937ab94a80cb4028ccb79441eae 100644 --- a/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/README.md +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework3/Weissenberger/README.md @@ -10,3 +10,30 @@ References include * [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/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/examples/src/HttpServletExamples/HttpWebPageSource.java b/examples/src/HttpServletExamples/HttpWebPageSource.java index 34f51cfb7397db064e1676071d1910f516f75ce9..97166ba5a0593ae53b1276d4e4377f454281d2cc 100644 --- a/examples/src/HttpServletExamples/HttpWebPageSource.java +++ b/examples/src/HttpServletExamples/HttpWebPageSource.java @@ -27,9 +27,13 @@ public class HttpWebPageSource { // We request an IP to connect to a web server running on default http port 80. - String WEB_ADDRESS = "www.nps.edu"; - System.out.println("New socket WEB_ADDRESS=" + WEB_ADDRESS); - Socket socket = new Socket(WEB_ADDRESS, 80); // compare alternative: https on port 443 + String WEB_SERVER_ADDRESS = "www.nps.edu"; + int WEB_SERVER_PORT_HTTP = 80; + int WEB_SERVER_PORT_HTTPS = 443; // does this work too? + System.out.println("New socket WEB_ADDRESS=" + WEB_SERVER_ADDRESS); + + // this Java construct will work for HTTP but not HTTPS + Socket socket = new Socket(WEB_SERVER_ADDRESS, WEB_SERVER_PORT_HTTPS); // compare alternative: https on port 443 // we send a command to the web server, asking for what // we want. Note that the format for the command is very diff --git a/examples/src/HttpServletExamples/HttpWebPageSourceTerminalLog.txt b/examples/src/HttpServletExamples/HttpWebPageSourceTerminalLog.txt index 896fb30c8a6329cb407929eec9a835ac16839a6d..9deeef11d9aede321dc7ed17c0795449fbb134d7 100644 --- a/examples/src/HttpServletExamples/HttpWebPageSourceTerminalLog.txt +++ b/examples/src/HttpServletExamples/HttpWebPageSourceTerminalLog.txt @@ -31,3 +31,34 @@ GET /index.html HTTP/1.0 15: </body></html> HttpWebPageSource: response finished BUILD SUCCESSFUL (total time: 2 seconds) + +now using https to port 443: + +run-single: +HttpWebPageSource: create http connection and retrieve default page +Reference: https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol +Reference: https://tools.ietf.org/html/rfc7230 +Reference: https://en.wikipedia.org/wiki/CURL + +New socket WEB_ADDRESS=www.nps.edu +GET /index.html HTTP/1.0 + +1: HTTP/1.1 400 Bad Request +2: Date: Mon, 17 Aug 2020 18:25:20 GMT +3: Server: Apache +4: Content-Length: 362 +5: Connection: close +6: Content-Type: text/html; charset=iso-8859-1 +7: +8: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> +9: <html><head> +10: <title>400 Bad Request</title> +11: </head><body> +12: <h1>Bad Request</h1> +13: <p>Your browser sent a request that this server could not understand.<br /> +14: Reason: You're speaking plain HTTP to an SSL-enabled server port.<br /> +15: Instead use the HTTPS scheme to access this URL, please.<br /> +16: </p> +17: </body></html> +HttpWebPageSource: response finished +BUILD SUCCESSFUL (total time: 2 seconds) diff --git a/examples/src/HttpServletExamples/JavaServletArchitecture.pdf b/examples/src/HttpServletExamples/JavaServletArchitecture.pdf new file mode 100644 index 0000000000000000000000000000000000000000..236c662b9c433cb23867a728adef739676412211 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..6397123bd2d2f528c79b8897c9a4cdbf85962727 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..f7c1df983ec0fc59aa767beb67dd6c9c0a331af6 Binary files /dev/null and b/examples/src/HttpServletExamples/JavaServletArchitecture.vsdx differ diff --git a/examples/src/UdpMulticastExamples/UdpSender.java b/examples/src/UdpMulticastExamples/UdpSender.java index 7005073ec0105f06141f35a5d4c4787bdc19dc96..8a658e878bb7ec212e666fc5ebeeea6b51617312 100644 --- a/examples/src/UdpMulticastExamples/UdpSender.java +++ b/examples/src/UdpMulticastExamples/UdpSender.java @@ -20,10 +20,12 @@ public class UdpSender { // 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; +// 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; - public static final String DESTINATION_HOST = "localhost"; // localhost 127.0.0.1 or argon 10.1.105.1 + + // here is what we need for lab comms + public static final String DESTINATION_HOST = "10.1.105.16"; // 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 @@ -32,8 +34,8 @@ public class UdpSender 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 = "Hello from " + MY_NAME; // no really - String padding; + String message = MY_NAME + " says Hello MV3500"; // no really + String padding = new String(); try { @@ -41,7 +43,7 @@ public class UdpSender System.out.println(UdpSender.class.getName() + " started..."); // Create a UDP socket - udpSocket = new DatagramSocket(); + 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 @@ -68,8 +70,8 @@ public class UdpSender 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 = 100 - packetID; // countdown + 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! @@ -82,6 +84,7 @@ public class UdpSender 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 = " ";