diff --git a/projects/Assignments/homework1/MyMulticastSender b/projects/Assignments/homework1/MyMulticastSender new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/projects/Assignments/homework2/Blankenbeker HW 2 UML.docx b/projects/Assignments/homework2/Blankenbeker HW 2 UML.docx new file mode 100644 index 0000000000000000000000000000000000000000..036c1d1e55e9d95d84fe19e072e033807a1c3a01 Binary files /dev/null and b/projects/Assignments/homework2/Blankenbeker HW 2 UML.docx differ diff --git a/projects/Assignments/homework2/BlankenbekerMulticastReceiver.java b/projects/Assignments/homework2/BlankenbekerMulticastReceiver.java new file mode 100644 index 0000000000000000000000000000000000000000..9a313ac7164bfc18b35c98bd75aa11235d6abfc1 --- /dev/null +++ b/projects/Assignments/homework2/BlankenbekerMulticastReceiver.java @@ -0,0 +1,71 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.net.DatagramPacket; +import java.net.InetAddress; +import java.net.MulticastSocket; + +/** + * + * @author Michael + */ +public class BlankenbekerMulticastReceiver { + + public static final String MULTICAST_ADDRESS = "239.1.2.15"; + public static final int DESTINATION_PORT = 1717; + /** How many routers can be crossed */ + public static final int TTL = 10; + + public static void main(String[] args) + { + try + { + + // This is a java/IPv6 problem. You should also add it to the + // arguments used to start the app, eg -Djava.net.preferIPv4Stack=true + // set in the "run" section of preferences. Also, typically + // netbeans must be restarted after these settings. + // https://stackoverflow.com/questions/18747134/getting-cant-assign-requested-address-java-net-socketexception-using-ehcache + System.setProperty("java.net.preferIPv4Stack", "true"); + + + MulticastSocket multicastSocket = new MulticastSocket(DESTINATION_PORT); + multicastSocket.setTimeToLive(TTL); + InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); + System.out.println(multicastAddress); + // Join group useful on receiving side + multicastSocket.joinGroup(multicastAddress); + // You can join multiple groups here + + int count = 0; + + while(true) + { + byte[] packetArray = new byte[1500]; + DatagramPacket packet = new DatagramPacket(packetArray, packetArray.length); + + multicastSocket.receive(packet); + count++; + + ByteArrayInputStream bais = new ByteArrayInputStream(packet.getData()); + DataInputStream dis = new DataInputStream(bais); + float firstNumber = dis.readFloat(); + float secondNumber = dis.readFloat(); + float thirdNumber = dis.readFloat(); + + System.out.println("Number received: " + count + " Vehicle position is: (" + firstNumber + ", " + secondNumber+", "+thirdNumber+")"); + } + } + catch(Exception e) + { + System.out.println(e); + } + } + +} diff --git a/projects/Assignments/homework2/BlankenbekerMulticastSender.java b/projects/Assignments/homework2/BlankenbekerMulticastSender.java new file mode 100644 index 0000000000000000000000000000000000000000..4207b1799abaad4ea1daa672e737ea9a5f1ddf95 --- /dev/null +++ b/projects/Assignments/homework2/BlankenbekerMulticastSender.java @@ -0,0 +1,92 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.net.DatagramPacket; +import java.net.InetAddress; +import java.net.MulticastSocket; + +/** + * + * @author Michael + */ +public class BlankenbekerMulticastSender { + + public static final String MULTICAST_ADDRESS = "239.1.2.15"; + public static final int DESTINATION_PORT = 1717; + /** How many routers can be crossed */ + public static final int TTL = 10; + + public static void main(String[] args) + { + Truck truck = new Truck(); + while (true) { + truck.move(); + try + { + // This is a java/IPv6 problem. You should also add it to the + // arguments used to start the app, eg -Djava.net.preferIPv4Stack=true + // set in the "run" section of preferences. Also, typically + // netbeans must be restarted after these settings. + // https://stackoverflow.com/questions/18747134/getting-cant-assign-requested-address-java-net-socketexception-using-ehcache + System.setProperty("java.net.preferIPv4Stack", "true"); + + + + MulticastSocket multicastSocket = new MulticastSocket(1718); + multicastSocket.setTimeToLive(TTL); + InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); + System.out.println(multicastAddress); + // Join group useful on receiving side + multicastSocket.joinGroup(multicastAddress); + // You can join multiple groups here + + // 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(); + DataOutputStream dos = new DataOutputStream(baos); + float x = truck.getX(); + float y = truck.getY(); + float z = truck.getZ(); + + dos.writeFloat(x); + dos.writeFloat(y); + dos.writeFloat(z); + + byte[] buffer = baos.toByteArray(); + + // Put together a packet to send + + // muticast group we are sending to--not a single host + + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, multicastAddress, DESTINATION_PORT); + + // How fast does this go? Does UDP try to slow it 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? + + for(int idx = 0; idx < 1; idx++) + { + + multicastSocket.send(packet); + Thread.sleep(1000); // Send 100, one per second + System.out.println("Sent new multicast packet 1 of 1"); + } + } + catch(Exception e) + { + System.out.println(e); + } + } + +} +} \ No newline at end of file diff --git a/projects/Assignments/homework2/ConardMulticastReceiver.java b/projects/Assignments/homework2/ConardMulticastReceiver.java new file mode 100644 index 0000000000000000000000000000000000000000..03e17de4228892706ab742bc752c34346f69cef9 --- /dev/null +++ b/projects/Assignments/homework2/ConardMulticastReceiver.java @@ -0,0 +1,65 @@ +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; +import java.net.MulticastSocket; +import java.net.UnknownHostException; +/** + * + * @author emilyconard + */ +public class ConardMulticastReceiver { + public static final String MULTICAST_ADDRESS = "239.1.2.15"; + public static final int DESTINATION_PORT = 1717; + /** How many routers can be crossed */ + public static final int TTL = 10; + + public static void main(String[] args) + { + try + { + + // This is a java/IPv6 problem. You should also add it to the + // arguments used to start the app, eg -Djava.net.preferIPv4Stack=true + // set in the "run" section of preferences. Also, typically + // netbeans must be restarted after these settings. + // https://stackoverflow.com/questions/18747134/getting-cant-assign-requested-address-java-net-socketexception-using-ehcache + System.setProperty("java.net.preferIPv4Stack", "true"); + + + MulticastSocket multicastSocket = new MulticastSocket(DESTINATION_PORT); + multicastSocket.setTimeToLive(TTL); + InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); + System.out.println(multicastAddress); + // Join group useful on receiving side + multicastSocket.joinGroup(multicastAddress); + // You can join multiple groups here + + int count = 0; + + while(true) + { + byte[] packetArray = new byte[1500]; + DatagramPacket packet = new DatagramPacket(packetArray, packetArray.length); + + multicastSocket.receive(packet); + count++; + + ByteArrayInputStream bais = new ByteArrayInputStream(packet.getData()); + DataInputStream dis = new DataInputStream(bais); + float firstNumber = dis.readInt(); + float secondNumber = dis.readInt(); + float thirdNumber = dis.readInt(); + + System.out.println("Number received: " + count + " ID: " + firstNumber + " xcord: " + secondNumber + " ycord: "+ thirdNumber); + } + } + catch(Exception e) + { + System.out.println(e); + } + } + +} diff --git a/projects/Assignments/homework2/ConardMulticastSender.java b/projects/Assignments/homework2/ConardMulticastSender.java new file mode 100644 index 0000000000000000000000000000000000000000..f2f0e96ebd2971515e31daf55a2cb04f23dd34e9 --- /dev/null +++ b/projects/Assignments/homework2/ConardMulticastSender.java @@ -0,0 +1,67 @@ + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; +import java.net.MulticastSocket; + + +/** + * + * @author emilyconard + */ +public class ConardMulticastSender { + + public static final String MULTICAST_ADDRESS = "239.1.2.15"; + public static final int DESTINATION_PORT = 1717; + /** How many routers can be crossed */ + public static final int TTL = 10; + + public static void main(String[] args) + { + try + { + int ID = 27; + int xcord = 5; + int ycord = 7; + System.setProperty("java.net.preferIPv4Stack", "true"); + + + MulticastSocket multicastSocket = new MulticastSocket(1718); + multicastSocket.setTimeToLive(TTL); + InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); + System.out.println(multicastAddress); + // Join group useful on receiving side + multicastSocket.joinGroup(multicastAddress); + // You can join multiple groups here + + // 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(); + DataOutputStream dos = new DataOutputStream(baos); + dos.writeInt(ID); + dos.writeInt(xcord); + dos.writeInt(ycord); + byte[] buffer = baos.toByteArray(); + + + + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, multicastAddress, DESTINATION_PORT); + + for(int idx = 0; idx < 100; idx++) + { + multicastSocket.send(packet); + Thread.sleep(1000); // Send 100, one per second + System.out.println("Sent multicast packet " + idx + " of 100"); + } + } + catch(Exception e) + { + System.out.println(e); + } + } + +} diff --git a/projects/Assignments/homework2/Sasala UML Diagram & Screen Shot (HW2).docx b/projects/Assignments/homework2/Sasala UML Diagram & Screen Shot (HW2).docx new file mode 100644 index 0000000000000000000000000000000000000000..211194bbc15369dccefa6c4c12c1173c55f91352 Binary files /dev/null and b/projects/Assignments/homework2/Sasala UML Diagram & Screen Shot (HW2).docx differ diff --git a/projects/Assignments/homework2/SasalaMulticastReceiver.java b/projects/Assignments/homework2/SasalaMulticastReceiver.java new file mode 100644 index 0000000000000000000000000000000000000000..5effc77a951fe3c571b9fe4dc0b889c4bb809e19 --- /dev/null +++ b/projects/Assignments/homework2/SasalaMulticastReceiver.java @@ -0,0 +1,60 @@ + + + +import java.io.*; +import java.net.*; + +/** + * + * @author mcgredo + */ +public class SasalaMulticastReceiver { + + public static final String MULTICAST_ADDRESS = "239.1.2.15"; + public static final int DESTINATION_PORT = 1717; + /** How many routers can be crossed */ + public static final int TTL = 10; + + public static void main(String[] args) + { + try + { + + // This is a java/IPv6 problem. You should also add it to the + // arguments used to start the app, eg -Djava.net.preferIPv4Stack=true + // set in the "run" section of preferences. Also, typically + // netbeans must be restarted after these settings. + // https://stackoverflow.com/questions/18747134/getting-cant-assign-requested-address-java-net-socketexception-using-ehcache + System.setProperty("java.net.preferIPv4Stack", "true"); + + + MulticastSocket multicastSocket = new MulticastSocket(DESTINATION_PORT); + multicastSocket.setTimeToLive(TTL); + InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); + System.out.println(multicastAddress); + // Join group useful on receiving side + multicastSocket.joinGroup(multicastAddress); + // You can join multiple groups here + + while(true) + { + byte[] packetArray = new byte[1500]; + DatagramPacket packet = new DatagramPacket(packetArray, packetArray.length); + + multicastSocket.receive(packet); + + ByteArrayInputStream bais = new ByteArrayInputStream(packet.getData()); + DataInputStream dis = new DataInputStream(bais); + float temperature = dis.readFloat(); + String DTG = dis.readLine(); + + System.out.println("Time: " + DTG + " Temperature:" + temperature); + } + } + catch(Exception e) + { + System.out.println(e); + } + } + +} diff --git a/projects/Assignments/homework2/SasalaMulticastSender.java b/projects/Assignments/homework2/SasalaMulticastSender.java new file mode 100644 index 0000000000000000000000000000000000000000..554b59fa7a678ed39c71ec2f4d608fd3e2bc3079 --- /dev/null +++ b/projects/Assignments/homework2/SasalaMulticastSender.java @@ -0,0 +1,74 @@ + + + +import java.io.*; +import java.net.*; +import java.time.LocalDateTime; + +/** + * Looks a lot like a UDP sender. + * + * @author mcgredo + */ +public class SasalaMulticastSender { + + public static final String MULTICAST_ADDRESS = "239.1.2.15"; + public static final int DESTINATION_PORT = 1717; + /** How many routers can be crossed */ + public static final int TTL = 10; + + public static void main(String[] args) + { + try + { + // This is a java/IPv6 problem. You should also add it to the + // arguments used to start the app, eg -Djava.net.preferIPv4Stack=true + // set in the "run" section of preferences. Also, typically + // netbeans must be restarted after these settings. + // https://stackoverflow.com/questions/18747134/getting-cant-assign-requested-address-java-net-socketexception-using-ehcache + System.setProperty("java.net.preferIPv4Stack", "true"); + + + MulticastSocket multicastSocket = new MulticastSocket(1718); + multicastSocket.setTimeToLive(TTL); + InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); + System.out.println(multicastAddress); + // Join group useful on receiving side + multicastSocket.joinGroup(multicastAddress); + // You can join multiple groups here + + // 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(); + DataOutputStream dos = new DataOutputStream(baos); + + for(int idx = 0; idx < 100; idx++) + { + double temperature = 100 * Math.random(); + LocalDateTime LDT = LocalDateTime.now(); + String time = LDT.toString(); + + dos.writeFloat((float) temperature); + dos.writeChars(time); + + // Put together a packet to send + // muticast group we are sending to--not a single host + byte[] buffer = baos.toByteArray(); + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, multicastAddress, DESTINATION_PORT); + + multicastSocket.send(packet); + Thread.sleep(1000); // Send 100, one per second + System.out.println("Sent multicast packet " + idx + " of 100"); + + baos.reset(); + } + } + catch(Exception e) + { + System.out.println(e); + } + } + +} diff --git a/projects/Assignments/homework2/Truck.java b/projects/Assignments/homework2/Truck.java new file mode 100644 index 0000000000000000000000000000000000000000..a1e40bf6243a2295286bcf3139f0f9e217fa4732 --- /dev/null +++ b/projects/Assignments/homework2/Truck.java @@ -0,0 +1,44 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package mv3500code; + +/** + * + * @author Michael + */ +public class Truck { + private float x; + private float y; + private float z; + + public Truck(){ + x = 0; + y=0; + z=0; + } + + public void move(){ + x+=1.5; + y+=1.2; + z-=.2; +} + /** + * + * @return + */ + public float getX(){ + return x; + } + + public float getY(){ + return y; + } + + public float getZ(){ + return z; + } +} + diff --git a/projects/Assignments/homework2/YamashitaDeMouraEntity.java b/projects/Assignments/homework2/YamashitaDeMouraEntity.java new file mode 100644 index 0000000000000000000000000000000000000000..4ad6f592bbf1e02c349d4e9e8e0478e8cb0f85b1 --- /dev/null +++ b/projects/Assignments/homework2/YamashitaDeMouraEntity.java @@ -0,0 +1,99 @@ + +/** + * MV3500 + * + * Entity + * + * @author Douglas Yamashita de Moura + * @version 20180227 + * + */ +public class YamashitaDeMouraEntity { + + private String name; + private float x; + private float y; + private float z; + private float speed; + + public YamashitaDeMouraEntity (String name, float x, float y, float z, float speed) { + this.name = name; + this.x = x; + this.y = y; + this.z = z; + this.speed = speed; + } + + /** + * @return the x + */ + public float getX() { + return x; + } + + /** + * @param x the x to set + */ + public void setX(float x) { + this.x = x; + } + + /** + * @return the y + */ + public float getY() { + return y; + } + + /** + * @param y the y to set + */ + public void setY(float y) { + this.y = y; + } + + /** + * @return the z + */ + public float getZ() { + return z; + } + + /** + * @param z the z to set + */ + public void setZ(float z) { + this.z = z; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the velocity + */ + public float getVelocity() { + return speed; + } + + /** + * @param velocity the velocity to set + */ + public void setVelocity(float velocity) { + this.speed = velocity; + } + + + +} diff --git a/projects/Assignments/homework2/YamashitaDeMouraMulticastReceiver.java b/projects/Assignments/homework2/YamashitaDeMouraMulticastReceiver.java new file mode 100644 index 0000000000000000000000000000000000000000..8cb018ba6f006609a3668ff1a1b524520598f5b9 --- /dev/null +++ b/projects/Assignments/homework2/YamashitaDeMouraMulticastReceiver.java @@ -0,0 +1,77 @@ + +import java.io.*; +import java.net.*; +import java.util.Random; + +/** + * MV3500 + * + * Multicast Receiver + * + * @author Douglas Yamashita de Moura + * @version 20180227 + * + */ +public class YamashitaDeMouraMulticastReceiver { + + public static final String MULTICAST_ADDRESS = "239.1.2.15"; + public static final int DESTINATION_PORT = 1717; + public static final int TTL = 10; + + public static void main(String[] args) + { + try + { + System.setProperty("java.net.preferIPv4Stack", "true"); + MulticastSocket multicastSocket = new MulticastSocket(DESTINATION_PORT); + multicastSocket.setTimeToLive(TTL); + InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); + System.out.println(multicastAddress); + multicastSocket.joinGroup(multicastAddress); + int count = 0; + + int randomReceiver = new Random().nextInt(100); + System.out.println("=== MULTICAST RECEIVER " + randomReceiver + " ==="); + + while(true) + { + byte[] packetArray = new byte[1500]; + DatagramPacket packet = new DatagramPacket(packetArray, packetArray.length); + multicastSocket.receive(packet); + count++; + ByteArrayInputStream bais = new ByteArrayInputStream(packet.getData()); + DataInputStream dis = new DataInputStream(bais); + char entity = dis.readChar(); + String name = ""; + int nameLength = 0; + switch(entity) { + case 'A': + nameLength = 4; + name = "A"; + break; + case 'B': + nameLength = 4; + name = "B"; + break; + } + + // Read name + for (int i = 0; i < nameLength; i++) { + name += dis.readChar(); + } + + // Read Position + float xPos = dis.readFloat(); + float yPos = dis.readFloat(); + float zPos = dis.readFloat(); + System.out.println("Entity '" + name + "' with position (" + xPos + + ", " + yPos + ", " + zPos +")."); + System.out.println("Number received: " + count); + } + } + catch(Exception e) + { + System.out.println(e); + } + } +} diff --git a/projects/Assignments/homework2/YamashitaDeMouraMulticastSender.java b/projects/Assignments/homework2/YamashitaDeMouraMulticastSender.java new file mode 100644 index 0000000000000000000000000000000000000000..725621ddb603e6c7aa43e7e1e328a681897e1dc2 --- /dev/null +++ b/projects/Assignments/homework2/YamashitaDeMouraMulticastSender.java @@ -0,0 +1,85 @@ + +import java.io.*; +import java.net.*; +import java.util.Random; + +/** + * MV3500 + * + * Multicast Sender + * + * @author Douglas Yamashita de Moura + * @version 20180227 + * + */ +public class YamashitaDeMouraMulticastSender { + + public static final String MULTICAST_ADDRESS = "239.1.2.15"; + public static final int DESTINATION_PORT = 1717; + public static final int TTL = 10; + + + public static void main(String[] args) + { + YamashitaDeMouraEntity entityA = new YamashitaDeMouraEntity("Alpha", 0, 0, 0, 2); + YamashitaDeMouraEntity entityB = new YamashitaDeMouraEntity("Bravo", 0, 0, 0, 3); + + try + { + System.setProperty("java.net.preferIPv4Stack", "true"); + + MulticastSocket multicastSocket = new MulticastSocket(1718); + multicastSocket.setTimeToLive(TTL); + InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); + System.out.println(multicastAddress); + multicastSocket.joinGroup(multicastAddress); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + + Random randomProb = new Random(); + + System.out.println("=== MULTICAST SENDER ==="); + + for(int idx = 1; idx < 100; idx++) + { + int prob = randomProb.nextInt(5); + + if(prob < 2) { + dos.writeChars(entityA.getName()); + // Move only in x direction + float newPos = entityA.getX()+entityA.getVelocity(); + entityA.setX(newPos); + dos.writeFloat(entityA.getX()); + dos.writeFloat(entityA.getY()); + dos.writeFloat(entityA.getZ()); + System.out.println("Entity '" + entityA.getName() + + "' with position (" + entityA.getX() + ", " + + entityA.getY() + ", " + entityA.getZ() + ")"); + } else if (prob < 5) { + dos.writeChars(entityB.getName()); + dos.writeFloat(entityB.getX()); + // Move only in y direction + float newPos = entityB.getY()+entityB.getVelocity(); + entityB.setY(newPos); + dos.writeFloat(entityB.getY()); + dos.writeFloat(entityB.getZ()); + System.out.println("Entity '" + entityB.getName() + + "' with position (" + entityB.getX() + ", " + + entityB.getY() + ", " + entityB.getZ() + ")"); + } + + byte[] buffer = baos.toByteArray(); + + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, multicastAddress, DESTINATION_PORT); + multicastSocket.send(packet); + baos.reset(); + Thread.sleep(1000); // Send 100, one per second + System.out.println("Sent multicast packet " + idx + " of 100"); + } + } + catch(Exception e) + { + System.out.println(e); + } + } +} diff --git a/projects/Assignments/homework2/YamashitaDeMouraOutput.jpg b/projects/Assignments/homework2/YamashitaDeMouraOutput.jpg new file mode 100644 index 0000000000000000000000000000000000000000..ea97fa9be246b0dadc110583cbd7032f1bac3886 Binary files /dev/null and b/projects/Assignments/homework2/YamashitaDeMouraOutput.jpg differ diff --git a/projects/Assignments/homework3/OpenDisPduSender.java b/projects/Assignments/homework3/OpenDisPduSender.java new file mode 100644 index 0000000000000000000000000000000000000000..77e4d8ce51c527df4d17c88bc740f388fba8493b --- /dev/null +++ b/projects/Assignments/homework3/OpenDisPduSender.java @@ -0,0 +1,164 @@ +package edu.nps.moves.examples; + +import java.io.*; +import java.net.*; +import java.util.*; + +import edu.nps.moves.dis.*; +import edu.nps.moves.disenum.*; + +/** + * This is an example that sends many/most types of PDUs. Useful for testing standards + * compliance or getting a full set of PDUs. It also writes the generated PDUs to + * an XML file. + * + * @author DMcG + * @version $Id:$ + */ +public class PduSender { + + public static final int PORT = 62040; + public static final String MULTICAST_ADDRESS = "239.1.2.3"; + private int port; + InetAddress multicastAddress; + + public PduSender(int port, String multicast) { + try { + this.port = port; + multicastAddress = InetAddress.getByName(multicast); + if (!multicastAddress.isMulticastAddress()) { + System.out.println("Not a multicast address: " + multicast); + } + } catch (Exception e) { + System.out.println("Unable to open socket"); + } + } + + public void run() { + try { + List<Pdu> generatedPdus = new ArrayList<Pdu>(); + + // Loop through all the enumerated PDU types, create a PDU for each type, + // and add that PDU to a list. + for (PduType pdu : PduType.values()) { + Pdu aPdu = null; + + switch (pdu) { + case ENTITY_STATE: + aPdu = new EntityStatePdu(); + break; + + case COMMENT: + aPdu = new CommentPdu(); + break; + + case FIRE: + aPdu = new FirePdu(); + break; + + case DETONATION: + aPdu = new DetonationPdu(); + break; + + case COLLISION: + aPdu = new CollisionPdu(); + break; + + case SERVICE_REQUEST: + aPdu = new ServiceRequestPdu(); + break; + + case RESUPPLY_OFFER: + aPdu = new ResupplyOfferPdu(); + break; + + case RESUPPLY_RECEIVED: + aPdu = new ResupplyReceivedPdu(); + break; + + case RESUPPLY_CANCEL: + aPdu = new ResupplyCancelPdu(); + break; + + case REPAIR_COMPLETE: + aPdu = new RepairCompletePdu(); + break; + + case REPAIR_RESPONSE: + aPdu = new RepairResponsePdu(); + break; + + case CREATE_ENTITY: + aPdu = new CreateEntityPdu(); + break; + + case REMOVE_ENTITY: + aPdu = new RemoveEntityPdu(); + break; + + case START_RESUME: + aPdu = new StartResumePdu(); + break; + + case STOP_FREEZE: + aPdu = new StopFreezePdu(); + break; + + case ACKNOWLEDGE: + aPdu = new AcknowledgePdu(); + break; + + case ACTION_REQUEST: + aPdu = new ActionRequestPdu(); + break; + + default: + System.out.print("PDU of type " + pdu + " not created or sent "); + System.out.println(); + } + + if (aPdu != null) { + generatedPdus.add(aPdu); + } + } + + // Sort the created PDUs by class name + Collections.sort(generatedPdus, new ClassNameComparator()); + + // Send the PDUs we created + InetAddress localMulticastAddress = InetAddress.getByName(MULTICAST_ADDRESS); + MulticastSocket socket = new MulticastSocket(PORT); + socket.joinGroup(localMulticastAddress); + + for (int idx = 0; idx < generatedPdus.size(); idx++) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + byte[] buffer; + + Pdu aPdu = generatedPdus.get(idx); + aPdu.marshal(dos); + + buffer = baos.toByteArray(); + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, PORT); + socket.send(packet); + System.out.println("Sent PDU of type " + aPdu.getClass().getName()); + } + + // write the PDUs out to an XML file. + //PduContainer container = new PduContainer(); + //container.setPdus(generatedPdus); + //container.marshallToXml("examplePdus.xml"); + } catch (Exception e) { + System.out.println(e); + } + } + + public static void main(String args[]) { + if (args.length == 2) { + PduSender sender = new PduSender(Integer.parseInt(args[0]), args[1]); + sender.run(); + } else { + System.out.println("Usage: PduSender <port> <multicast group>"); + } + } +} diff --git a/projects/Assignments/homework3/README.md b/projects/Assignments/homework3/README.md new file mode 100644 index 0000000000000000000000000000000000000000..3aec0c650be10db070657a62627fccd20f1c60e3 --- /dev/null +++ b/projects/Assignments/homework3/README.md @@ -0,0 +1,15 @@ +# Homework Assignment 3 (draft) + +1. Add X3D-Edit as Netbeans Plugin from https://savage.nps.edu/X3D-Edit/#Downloads + +1. Checkout Open-DIS-Java library from https://github.com/open-dis/open-dis-java + +1. Plan a track of interest, described in YournameREADME.md documentation file... + +1. Modify example file OpenDisPduSender... + +1. Generate PDUs... + +1. Record PDU file using X3D-Edit... + +1. Playback PDU file using X3D-Edit... \ No newline at end of file