diff --git a/CourseExamples/nbproject/genfiles.properties b/CourseExamples/nbproject/genfiles.properties index 6bfdbedf4d07e3d4c841ae90be62147217121909..47cc2bb96ce7b73637ab2a3cd11fc847dc7e4026 100644 --- a/CourseExamples/nbproject/genfiles.properties +++ b/CourseExamples/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=ba18aca8 +build.xml.data.CRC32=3397fc52 build.xml.script.CRC32=f4fc0484 build.xml.stylesheet.CRC32=8064a381@1.80.1.48 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=ba18aca8 +nbproject/build-impl.xml.data.CRC32=3397fc52 nbproject/build-impl.xml.script.CRC32=6a5b91f6 nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/CourseExamples/src/DisExamples/PduSender.java b/CourseExamples/src/DisExamples/PduSender.java index 9462fec0e2f784052727a3be19abe68cf2fdd9ef..9d92a3b353df8bf6bfd93dc287d8fd601e2902d9 100644 --- a/CourseExamples/src/DisExamples/PduSender.java +++ b/CourseExamples/src/DisExamples/PduSender.java @@ -73,6 +73,9 @@ public class PduSender case COMMENT: aPdu = new CommentPdu(); + CommentPdu newCommentPdu = (CommentPdu)aPdu; + VariableDatum newVariableDatum = new VariableDatum(); + // etc. see Garrett and Pete's code break; case FIRE: diff --git a/CourseExamples/src/TcpExamples/TcpExample3Server.java b/CourseExamples/src/TcpExamples/TcpExample3Server.java index 1ed761bf53c8fbfe9c8b88158921e4f0b4f795cc..eeccda6f4bb813ebb8c1296b6424a9837832bd9d 100644 --- a/CourseExamples/src/TcpExamples/TcpExample3Server.java +++ b/CourseExamples/src/TcpExamples/TcpExample3Server.java @@ -31,7 +31,7 @@ public class TcpExample3Server { // 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 + System.out.println("TcpExample3Server has really started..."); // it helps debugging to put this on console first ServerSocket serverSocket = new ServerSocket(2317); // Server is up and waiting (i.e. "blocked" or paused) @@ -62,7 +62,7 @@ public class TcpExample3Server { // // Why is the first IP/port the same, while the second set has // different ports? - System.out.println("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " + System.out.println("TcpExample3Server socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " + remoteAddress.toString() + ", " + remotePort + " ))"); // Notice the use of flush() and close(). Without diff --git a/CourseExamples/src/TcpExamples/TcpExample3TerminalLog.txt b/CourseExamples/src/TcpExamples/TcpExample3TerminalLog.txt index 1b670fe80f2ab8948257202532c5f7cc5d1b4a0c..af6c6b8bec360baec1855ac17bf99dc7aab4da7d 100644 --- a/CourseExamples/src/TcpExamples/TcpExample3TerminalLog.txt +++ b/CourseExamples/src/TcpExamples/TcpExample3TerminalLog.txt @@ -7,9 +7,9 @@ Program responses: =================================================== run: TcpExample3Server has started... -Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 49239 )) -Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 49240 )) -Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 49241 )) +TcpExample3Server socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 49239 )) +TcpExample3Server socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 49240 )) +TcpExample3Server socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 49241 )) [etc.] [kill process to exit] @@ -30,3 +30,7 @@ The message the server sent was This was written by the server TcpExample3Client creating socket... ================================================== [etc.] + +You must kill this process to get it to stop, each is in an infinite loop. + +If you kill the server, that will kill the client automatically when the connection drops. diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/CainThomersonFinal/ReadMe.txt b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/CainThomersonFinal/ReadMe.txt new file mode 100644 index 0000000000000000000000000000000000000000..192e01bdbf26272edb56494a5f7fb020c9137a1b --- /dev/null +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/CainThomersonFinal/ReadMe.txt @@ -0,0 +1,100 @@ +Final Project Notes: + +We constructed code to communicate between parties via DIS over a LAN (Local Area Network). +The PDU and Espdu example files were the genesis of the two files. + +To run our code you need to open two main classes + C_T_EspduRequestingUnit.java, and C_T_EspduSupplyingUnit.java + +In order to get the program to run properly, execute: +First: C_T_EspduSupplyingUnit.java +Next: C_T_EspduRequestingUnit.java + +Each class has the capability to both sender and receive packages. They are listening +for specific types of PDU packets, and will then send a response accordingly. + +Below is the output from running the code- + +-------------------- EspduSupplyingUnit output ------------------------------- + +SUPPLYER UNIT: + Program started + +SUPPYER UNIT: + Listening + +RECEIVED PACKET + Packet Type: edu.nps.moves.dis.EntityStatePdu + EID:[1, 1, 2] + Entity Location: [-2707492.9269245286, -4353663.899966802, 3781450.3202754413] + Entity Type: 1 + +SENDING ENTITY STATE PACKET + EID=[2,2,2] + Entity Location: [-1534805.049164391, 585379.2141969808, 6142318.841117044] + Entity Type: 7 + +RECEIVED PACKET + Packet Type: edu.nps.moves.dis.ServiceRequestPdu + Requesting Entity ID:[1, 1, 2] + Service Type Requested: [1, Resupply] + +SENDING PACKET + Packet Type: Resupply Offer + Receiving Entity ID: [1, 1, 2] + Supplying Entity ID: [2, 2, 2] + +RECEIVED PACKET + Packet Type: edu.nps.moves.dis.AcknowledgePdu +SENDING PACKET + Packet Type: Acknowledge + +SUPPYER UNIT: + Listening + +-------------------- EspduRequestingUnit output ------------------------------ + +REQUESTING UNIT: + Program started + +REQUESTING UNIT: + Listening + +SENDING ENTITY STATE INFORMATION + EID=[1,1,2] + Entity Location: [-2707492.9269245286, -4353663.899966802, 3781450.3202754413] + Entity Type: 1 + +RECEIVED PACKET + Packet Type: edu.nps.moves.dis.EntityStatePdu + EID:[2, 2, 2] + Entity Location: [-1534805.049164391, 585379.2141969808, 6142318.841117044] + Entity Type: 7 + +SENDING SERVICE REQUEST + Entity Requesting:[1, 1, 2] + Service Type Requested: [1, Resupply] + +SENDING SERVICE REQUEST + Entity Requesting:[1, 1, 2] + Service Type Requested: [1, Resupply] + +SENDING SERVICE REQUEST + Entity Requesting:[1, 1, 2] + Service Type Requested: [1, Resupply] + +RECEIVED PACKET + Packet Type: edu.nps.moves.dis.ResupplyOfferPdu + Supplying Unit: [2, 2, 2] + Requesting Unit: [1, 1, 2] + +SENDING ACKNOWLEDGE + +SENDING ACKNOWLEDGE + +SENDING ACKNOWLEDGE + +RECEIVED PACKET + Packet Type: edu.nps.moves.dis.AcknowledgePdu + +REQUEST COMPLETED - SOCKET IS NOW CLOSED \ No newline at end of file diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageReceiver.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageReceiver.java new file mode 100644 index 0000000000000000000000000000000000000000..80c12c8e7787b46cfe78e8f129cbb22d9d05748a --- /dev/null +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageReceiver.java @@ -0,0 +1,122 @@ +/* + * 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 MV3500Cohort2018JulySeptember.FinalProject.LoeffelmanSeverson; + +import edu.nps.moves.dis.CommentPdu; +import edu.nps.moves.dis.EntityID; +import edu.nps.moves.dis.EntityStatePdu; +import edu.nps.moves.dis.Pdu; +import edu.nps.moves.dis.OneByteChunk; +import edu.nps.moves.dis.VariableDatum; +import edu.nps.moves.dis.Vector3Double; +import edu.nps.moves.disutil.PduFactory; +import java.awt.Image; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.InetAddress; +import java.net.MulticastSocket; +import java.util.Iterator; +import java.util.List; +import javax.imageio.ImageIO; +import javax.swing.ImageIcon; +import javax.swing.JFrame; +import javax.swing.JLabel; +import edu.nps.moves.disenum.PduType; +import java.util.ArrayList; + +/** + * + * @author garrettloeffelman + */ +public class LoeffelmanSeversonDISImageReceiver { + + public static final int MULTICAST_PORT = 3000; + public static final String MULTICAST_GROUP = "239.1.2.15"; + public static final boolean USE_FAST_ESPDU = false; + + public static void main(String args[]) + { + Image image = null; + PduFactory factory; + MulticastSocket socket = null; + InetAddress address = null; + DatagramPacket packet; + + try + { + System.setProperty("java.net.preferIPv4Stack", "true"); + System.out.println("DisExamples.PduReceiver started..."); + socket = new MulticastSocket (MULTICAST_PORT); + address = InetAddress.getByName(MULTICAST_GROUP); + socket.joinGroup(address); + + factory = new PduFactory(); + + while (true) // Loop infinitely, receiving datagrams + { + byte buffer[] = new byte[100000]; // typical MTU size + + packet = new DatagramPacket(buffer, buffer.length); // reset + + socket.receive(packet); + + Pdu pdu = factory.createPdu (packet.getData()); + if (pdu != null) + { + short pduType = pdu.getPduType(); + String pduTypeName = pdu.getClass().getName(); + short protocolFamily = pdu.getProtocolFamily(); // TODO get string enumeration + + if(pdu.getPduTypeEnum() == PduType.COMMENT){ + CommentPdu cPdu = (CommentPdu)pdu; + ArrayList<VariableDatum> payload = (ArrayList)cPdu.getVariableDatums(); + VariableDatum payloadWrapper = payload.get(0); + ArrayList<OneByteChunk> oBC = (ArrayList)payloadWrapper.getVariableData(); + + byte[] imageByte = new byte[100000]; + + for(int i = 0; i < oBC.size(); i++){ + imageByte[i] = oBC.get(i).getOtherParameters()[0]; + } + + ByteArrayInputStream bais = new ByteArrayInputStream(imageByte); + BufferedImage bimage = ImageIO.read(bais); + image = bimage; + JFrame frame = new JFrame(); + frame.setSize(300, 300); + JLabel label = new JLabel(new ImageIcon(image)); + frame.add(label); + frame.setVisible(true); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } + + + StringBuilder message = new StringBuilder(); + message.append("received DIS PDU: "); + message.append("pduType "); + if (pduType < 10) + message.append(" "); + message.append(pduType).append(" ").append(pduTypeName); + message.append(", protocolFamily=").append(protocolFamily); + System.out.println(message.toString()); + } + else System.out.println("received packet but pdu is null, packet.getData().length=" + packet.getData().length + ", error..."); + + } + } + catch (IOException e) + { + System.out.println("Problem with DisExamples.PduReceiver, see exception trace:"); + System.out.println(e); + } + finally + { + System.out.println("DisExamples.PduReceiver complete."); + } + } +} diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageSender.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageSender.java new file mode 100644 index 0000000000000000000000000000000000000000..ac4fbc8a02aa194ad9ee3600c726556612223ef1 --- /dev/null +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageSender.java @@ -0,0 +1,252 @@ +/* + * 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 MV3500Cohort2018JulySeptember.FinalProject.LoeffelmanSeverson; + +import edu.nps.moves.dis.AcknowledgePdu; +import edu.nps.moves.dis.ActionRequestPdu; +import edu.nps.moves.dis.CollisionPdu; +import edu.nps.moves.dis.CommentPdu; +import edu.nps.moves.dis.CreateEntityPdu; +import edu.nps.moves.dis.DetonationPdu; +import edu.nps.moves.dis.EntityID; +import edu.nps.moves.dis.EntityStatePdu; +import edu.nps.moves.dis.EntityType; +import edu.nps.moves.dis.FirePdu; +import edu.nps.moves.dis.Pdu; +import edu.nps.moves.dis.VariableDatum; +import edu.nps.moves.dis.RemoveEntityPdu; +import edu.nps.moves.dis.RepairCompletePdu; +import edu.nps.moves.dis.RepairResponsePdu; +import edu.nps.moves.dis.ResupplyCancelPdu; +import edu.nps.moves.dis.ResupplyOfferPdu; +import edu.nps.moves.dis.ResupplyReceivedPdu; +import edu.nps.moves.dis.ServiceRequestPdu; +import edu.nps.moves.dis.StartResumePdu; +import edu.nps.moves.dis.StopFreezePdu; +import edu.nps.moves.dis.Vector3Double; +import edu.nps.moves.disenum.PduType; +import edu.nps.moves.disutil.CoordinateConversions; +import edu.nps.moves.disutil.DisTime; +import edu.nps.moves.dis.OneByteChunk; +import edu.nps.moves.examples.ClassNameComparator; +import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.InetAddress; +import java.net.InterfaceAddress; +import java.net.MalformedURLException; +import java.net.MulticastSocket; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.URL; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.imageio.ImageIO; + +/** + * + * @author garrettloeffelman + */ +public class LoeffelmanSeversonDISImageSender { + + /** Default multicast group address we send on. */ + public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.15"; + + /** Default multicast port used, matches Wire-shark DIS capture default */ + public static final int DEFAULT_MULTICAST_PORT = 3000; + + private int port; + InetAddress multicastAddress; + + public LoeffelmanSeversonDISImageSender (int port, String multicast) { + try + { + System.setProperty("java.net.preferIPv4Stack", "true"); + this.port = port; + multicastAddress = InetAddress.getByName(multicast); + if (!multicastAddress.isMulticastAddress()) + { + System.out.println("Not a multicast address: " + multicast); + } + } + catch (UnknownHostException e) { + System.out.println("Unable to open socket: " + e); + } + } + + public void run() + { + System.out.println("DisExamples.PduSender started..."); + try { + URL url1 = new URL("https://cdn1.iconfinder.com/data/icons/cute-monkey-emoticon/595/MONKEY_EMOTICON-05-512.png"); + URL url2 = new URL("https://images.all-free-download.com/images/graphicthumb/yammi_banana_99225.jpg"); + List<Pdu> generatedPdus = new ArrayList<>(); + + // 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) // using enumeration values from edu.nps.moves.disenum.* + { + case ENTITY_STATE: + aPdu = new EntityStatePdu(); + break; + + case COMMENT: + aPdu = new CommentPdu(); + CommentPdu cPdu = (CommentPdu)aPdu; + BufferedImage image = ImageIO.read(url1); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ImageIO.write(image, "png", baos); + byte[] buffer; + buffer = baos.toByteArray(); + ArrayList<VariableDatum> payload = new ArrayList<VariableDatum>(); + ArrayList<OneByteChunk> payloadWrapper = new ArrayList<OneByteChunk>(); + VariableDatum variableDatum = new VariableDatum(); + for(int i = 0; i < buffer.length; i++){ + OneByteChunk oBC = new OneByteChunk(); + byte[] oneBite = new byte[1]; + oneBite[0] = buffer[i]; + oBC.setOtherParameters(oneBite); + payloadWrapper.add(oBC); + } + System.out.println("Sending Picture"); + + variableDatum.setVariableData(payloadWrapper); + + payload.add(variableDatum); + cPdu.setVariableDatums(payload); + 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 supported, 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(DEFAULT_MULTICAST_ADDRESS); + MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_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, DEFAULT_MULTICAST_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 (IOException e) + { + System.out.println(e); + } + } + + public static void main(String args[]) + { + if (args.length == 2) { + LoeffelmanSeversonDISImageSender sender = new LoeffelmanSeversonDISImageSender(Integer.parseInt(args[0]), args[1]); + sender.run(); + } else { + System.out.println("Usage: PduSender <port> <multicast group>"); + System.out.println("Default: PduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); + LoeffelmanSeversonDISImageSender sender = new LoeffelmanSeversonDISImageSender(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); + sender.run(); + } + } +} diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/ReadMe.txt b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/ReadMe.txt new file mode 100644 index 0000000000000000000000000000000000000000..7e6324cbc7ef7cb0c31e89f05965b8da00ab3b8c Binary files /dev/null and b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/ReadMe.txt differ diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/LoeffelmanSeverson/LoeffelmanSeversonDISImageReceiver.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/LoeffelmanSeverson/LoeffelmanSeversonDISImageReceiver.java new file mode 100644 index 0000000000000000000000000000000000000000..bff3d5235fbe499aedb3a6beecc897f17a9234e3 --- /dev/null +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/LoeffelmanSeverson/LoeffelmanSeversonDISImageReceiver.java @@ -0,0 +1,133 @@ +/* + * 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 MV3500Cohort2018JulySeptember.FinalProjects.LoeffelmanSeverson; + +import edu.nps.moves.dis.CommentPdu; +import edu.nps.moves.dis.EntityID; +import edu.nps.moves.dis.EntityStatePdu; +import edu.nps.moves.dis.Pdu; +import edu.nps.moves.dis.OneByteChunk; +import edu.nps.moves.dis.VariableDatum; +import edu.nps.moves.dis.Vector3Double; +import edu.nps.moves.disutil.PduFactory; +import java.awt.Image; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.InetAddress; +import java.net.MulticastSocket; +import java.util.Iterator; +import java.util.List; +import javax.imageio.ImageIO; +import javax.swing.ImageIcon; +import javax.swing.JFrame; +import javax.swing.JLabel; +import edu.nps.moves.disenum.PduType; +import java.util.ArrayList; + +/** + * + * @author garrettloeffelman + */ +public class LoeffelmanSeversonDISImageReceiver { + + public static final int MULTICAST_PORT = 3000; + public static final String MULTICAST_GROUP = "239.1.2.15"; + public static final boolean USE_FAST_ESPDU = false; + + public static void main(String args[]) + { + Image image = null; + PduFactory factory; + MulticastSocket socket = null; + InetAddress address = null; + DatagramPacket packet; + + try + { + System.setProperty("java.net.preferIPv4Stack", "true"); + System.out.println("DisExamples.PduReceiver started..."); + socket = new MulticastSocket (MULTICAST_PORT); + address = InetAddress.getByName(MULTICAST_GROUP); + socket.joinGroup(address); + + factory = new PduFactory(); + + while (true) // Loop infinitely, receiving datagrams + { + //buffer needs to be resized to be able to accept image sizes + byte buffer[] = new byte[100000]; // typical MTU size + + packet = new DatagramPacket(buffer, buffer.length); // reset + + socket.receive(packet); + + Pdu pdu = factory.createPdu (packet.getData()); + if (pdu != null) + { + short pduType = pdu.getPduType(); + String pduTypeName = pdu.getClass().getName(); + short protocolFamily = pdu.getProtocolFamily(); // TODO get string enumeration + + //If we receive a comment PDU, we are going to look for a picture specifically + if(pdu.getPduTypeEnum() == PduType.COMMENT){ + //Set up data structures, get the list of variableDatums, and + //get the first and only VariableDatum, and the arrayList + //of OneByteChunks from the variableDatum + CommentPdu cPdu = (CommentPdu)pdu; + ArrayList<VariableDatum> payload = (ArrayList)cPdu.getVariableDatums(); + VariableDatum payloadWrapper = payload.get(0); + ArrayList<OneByteChunk> oBC = (ArrayList)payloadWrapper.getVariableData(); + + byte[] imageByte = new byte[100000]; + + //Loop through the arrayList of OneByteChunks and + //populate the byte array representation of the image + for(int i = 0; i < oBC.size(); i++){ + imageByte[i] = oBC.get(i).getOtherParameters()[0]; + } + + //Convert that byte array into an input stream and into + //an image using a buffered image reader. + ByteArrayInputStream bais = new ByteArrayInputStream(imageByte); + BufferedImage bimage = ImageIO.read(bais); + image = bimage; + + //Display the image using java swing utilities + JFrame frame = new JFrame(); + frame.setSize(300, 300); + JLabel label = new JLabel(new ImageIcon(image)); + frame.add(label); + frame.setVisible(true); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } + + + StringBuilder message = new StringBuilder(); + message.append("received DIS PDU: "); + message.append("pduType "); + if (pduType < 10) + message.append(" "); + message.append(pduType).append(" ").append(pduTypeName); + message.append(", protocolFamily=").append(protocolFamily); + System.out.println(message.toString()); + } + else System.out.println("received packet but pdu is null, packet.getData().length=" + packet.getData().length + ", error..."); + + } + } + catch (IOException e) + { + System.out.println("Problem with DisExamples.PduReceiver, see exception trace:"); + System.out.println(e); + } + finally + { + System.out.println("DisExamples.PduReceiver complete."); + } + } +} diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/LoeffelmanSeverson/LoeffelmanSeversonDISImageSender.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/LoeffelmanSeverson/LoeffelmanSeversonDISImageSender.java new file mode 100644 index 0000000000000000000000000000000000000000..68fa698cccb5c6549404eb992fed99fd02e5c254 --- /dev/null +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/LoeffelmanSeverson/LoeffelmanSeversonDISImageSender.java @@ -0,0 +1,262 @@ +/* + * 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 MV3500Cohort2018JulySeptember.FinalProjects.LoeffelmanSeverson; + +import edu.nps.moves.dis.AcknowledgePdu; +import edu.nps.moves.dis.ActionRequestPdu; +import edu.nps.moves.dis.CollisionPdu; +import edu.nps.moves.dis.CommentPdu; +import edu.nps.moves.dis.CreateEntityPdu; +import edu.nps.moves.dis.DetonationPdu; +import edu.nps.moves.dis.EntityID; +import edu.nps.moves.dis.EntityStatePdu; +import edu.nps.moves.dis.EntityType; +import edu.nps.moves.dis.FirePdu; +import edu.nps.moves.dis.Pdu; +import edu.nps.moves.dis.VariableDatum; +import edu.nps.moves.dis.RemoveEntityPdu; +import edu.nps.moves.dis.RepairCompletePdu; +import edu.nps.moves.dis.RepairResponsePdu; +import edu.nps.moves.dis.ResupplyCancelPdu; +import edu.nps.moves.dis.ResupplyOfferPdu; +import edu.nps.moves.dis.ResupplyReceivedPdu; +import edu.nps.moves.dis.ServiceRequestPdu; +import edu.nps.moves.dis.StartResumePdu; +import edu.nps.moves.dis.StopFreezePdu; +import edu.nps.moves.dis.Vector3Double; +import edu.nps.moves.disenum.PduType; +import edu.nps.moves.disutil.CoordinateConversions; +import edu.nps.moves.disutil.DisTime; +import edu.nps.moves.dis.OneByteChunk; +import edu.nps.moves.examples.ClassNameComparator; +import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.InetAddress; +import java.net.InterfaceAddress; +import java.net.MalformedURLException; +import java.net.MulticastSocket; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.URL; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.imageio.ImageIO; + +/** + * + * @author garrettloeffelman + */ +public class LoeffelmanSeversonDISImageSender { + + /** Default multicast group address we send on. */ + public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.15"; + + /** Default multicast port used, matches Wire-shark DIS capture default */ + public static final int DEFAULT_MULTICAST_PORT = 3000; + + private int port; + InetAddress multicastAddress; + + public LoeffelmanSeversonDISImageSender (int port, String multicast) { + try + { + System.setProperty("java.net.preferIPv4Stack", "true"); + this.port = port; + multicastAddress = InetAddress.getByName(multicast); + if (!multicastAddress.isMulticastAddress()) + { + System.out.println("Not a multicast address: " + multicast); + } + } + catch (UnknownHostException e) { + System.out.println("Unable to open socket: " + e); + } + } + + public void run() + { + System.out.println("DisExamples.PduSender started..."); + try { + URL url1 = new URL("https://cdn1.iconfinder.com/data/icons/cute-monkey-emoticon/595/MONKEY_EMOTICON-05-512.png"); + URL url2 = new URL("https://images.all-free-download.com/images/graphicthumb/yammi_banana_99225.jpg"); + List<Pdu> generatedPdus = new ArrayList<>(); + + // 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) // using enumeration values from edu.nps.moves.disenum.* + { + case ENTITY_STATE: + aPdu = new EntityStatePdu(); + break; + + case COMMENT: + //Initialize PDU and image + aPdu = new CommentPdu(); + CommentPdu cPdu = (CommentPdu)aPdu; + BufferedImage image = ImageIO.read(url1); + + //Convert image to a byte array + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ImageIO.write(image, "png", baos); + byte[] buffer; + buffer = baos.toByteArray(); + + //Instaniate data structures for holding bytes + ArrayList<VariableDatum> payload = new ArrayList<VariableDatum>(); + ArrayList<OneByteChunk> payloadWrapper = new ArrayList<OneByteChunk>(); + VariableDatum variableDatum = new VariableDatum(); + + //Loop through, create OneByteChunk arrays of size 1 + //and place them in ArrayList of OneByteChunks + for(int i = 0; i < buffer.length; i++){ + OneByteChunk oBC = new OneByteChunk(); + byte[] oneBite = new byte[1]; + oneBite[0] = buffer[i]; + oBC.setOtherParameters(oneBite); + payloadWrapper.add(oBC); + } + System.out.println("Sending Picture"); + + //Add the arrayList of OneByteChunks to the variable datum + variableDatum.setVariableData(payloadWrapper); + + //Add the variableDatum to the arraylist + payload.add(variableDatum); + //Set the variableDatum for the PDU to be sent + cPdu.setVariableDatums(payload); + 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 supported, 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(DEFAULT_MULTICAST_ADDRESS); + MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_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, DEFAULT_MULTICAST_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 (IOException e) + { + System.out.println(e); + } + } + + public static void main(String args[]) + { + if (args.length == 2) { + LoeffelmanSeversonDISImageSender sender = new LoeffelmanSeversonDISImageSender(Integer.parseInt(args[0]), args[1]); + sender.run(); + } else { + System.out.println("Usage: PduSender <port> <multicast group>"); + System.out.println("Default: PduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); + LoeffelmanSeversonDISImageSender sender = new LoeffelmanSeversonDISImageSender(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); + sender.run(); + } + } +} diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/README.md b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/README.md index 90da34a44cd5f0ee4352ccc596923d2d561809ca..42331e4aa93671d34b6c12c3ab037a94bd98240d 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/README.md +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/README.md @@ -5,3 +5,10 @@ Create a dedicated subdirectory for each individual or team project. Example: `SmithJones` See the [course syllabus](../../../../MV3500NetworkedGraphicsSyllabus2018JulySeptember.pdf) for details on how to document your project. + +Typical final project deliverables: +* README.md providing a basic description of goals, running the project, files, etc. +* Source code, screen shots, console text log, and any other assets +* Powerpoint presentation, video capture (if you want) + +These deliverables have great value going forward. Questions welcome, keep going! diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoServer.java b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoServer.java index 8cf008e867d34268c2891a008fad2a9faab8ef7f..7e2fcbbe2c330b535efaaeae4c7a089b2ae4414c 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoServer.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoServer.java @@ -55,7 +55,7 @@ public class DemchkoServer { // // Why is the first IP/port the same, while the second set has // different ports? - System.out.println("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " + System.out.println("Socket pair: (( " + localAddress.toString().trim() + ", " + localPort + " ), ( " + remoteAddress.toString() + ", " + remotePort + " ))"); InputStream is = clientConnection.getInputStream(); diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/homework3/Ayres_Demchko_Homework3/AyresDemchkoMulticastReceiver.java b/deliverables/src/MV3500Cohort2018JulySeptember/homework3/AyresDemchkoHomework3/AyresDemchkoMulticastReceiver.java similarity index 94% rename from deliverables/src/MV3500Cohort2018JulySeptember/homework3/Ayres_Demchko_Homework3/AyresDemchkoMulticastReceiver.java rename to deliverables/src/MV3500Cohort2018JulySeptember/homework3/AyresDemchkoHomework3/AyresDemchkoMulticastReceiver.java index acb89ce19013056d01ecc5efde1bd888eeab958f..f8e2c662592fe54c94ed14a357719f20e868b346 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/homework3/Ayres_Demchko_Homework3/AyresDemchkoMulticastReceiver.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/homework3/AyresDemchkoHomework3/AyresDemchkoMulticastReceiver.java @@ -3,7 +3,7 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package MV3500Cohort2018JulySeptember.homework3.Ayres_Homework3; +package MV3500Cohort2018JulySeptember.homework3.AyresDemchkoHomework3; import java.io.ByteArrayInputStream; import java.io.DataInputStream; @@ -17,7 +17,7 @@ import java.net.UnknownHostException; * * @author kjayr */ -public class AyresMulticastReceiver { +public class AyresDemchkoMulticastReceiver { public static final String MULTICAST_ADDRESS = "239.1.2.15"; public static final int DESTINATION_PORT = 1717; /** How many routers can be crossed */ diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/homework3/Ayres_Demchko_Homework3/AyresDemchkoMulticastSender.java b/deliverables/src/MV3500Cohort2018JulySeptember/homework3/AyresDemchkoHomework3/AyresDemchkoMulticastSender.java similarity index 92% rename from deliverables/src/MV3500Cohort2018JulySeptember/homework3/Ayres_Demchko_Homework3/AyresDemchkoMulticastSender.java rename to deliverables/src/MV3500Cohort2018JulySeptember/homework3/AyresDemchkoHomework3/AyresDemchkoMulticastSender.java index 6cee1718828b4ad7d79cab2a6ed91a19794abffc..b4a2e66cd2755794414fd4da4f50ce6033c196e1 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/homework3/Ayres_Demchko_Homework3/AyresDemchkoMulticastSender.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/homework3/AyresDemchkoHomework3/AyresDemchkoMulticastSender.java @@ -3,7 +3,7 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package MV3500Cohort2018JulySeptember.homework3.Ayres_Homework3; +package MV3500Cohort2018JulySeptember.homework3.AyresDemchkoHomework3; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; @@ -15,7 +15,7 @@ import java.net.MulticastSocket; * * @author kjayr */ -public class AyresMulticastSender { +public class AyresDemchkoMulticastSender { public static final String MULTICAST_ADDRESS = "239.1.2.15"; public static final int DESTINATION_PORT = 1717; diff --git a/nbproject/project.xml b/nbproject/project.xml index a1ff0804ded2f5d6f288471269665cbca996216b..02ebbf617cd659e035e70e2c2bdeab7f956b8a9f 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -18,12 +18,22 @@ auxiliary.show.customizer.message=<message> <source-folder> <label>Networked Graphics MV3500</label> <location>.</location> - <encoding>UTF-8</encoding> + <encoding>windows-1252</encoding> + </source-folder> + <source-folder> + <label>lib</label> + <type>java</type> + <location>lib</location> + <encoding>windows-1252</encoding> </source-folder> </folders> <ide-actions/> <view> <items> + <source-folder style="packages"> + <label>lib</label> + <location>lib</location> + </source-folder> <source-file> <location>build.xml</location> </source-file> @@ -32,7 +42,12 @@ auxiliary.show.customizer.message=<message> </view> <subprojects/> </general-data> - <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/1"/> + <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/1"> + <compilation-unit> + <package-root>lib</package-root> + <source-level>1.5</source-level> + </compilation-unit> + </java-data> <spellchecker-wordlist xmlns="http://www.netbeans.org/ns/spellchecker-wordlist/1"> <word>codebases</word> <word>DIS</word> @@ -40,6 +55,7 @@ auxiliary.show.customizer.message=<message> <word>interoperability</word> <word>interoperable</word> <word>TENA</word> + <word>Wikipedia</word> </spellchecker-wordlist> </configuration> </project>