diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageReceiver.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageReceiver.java index 80c12c8e7787b46cfe78e8f129cbb22d9d05748a..38005da451a4fe0a6cb6593400bdb68f915d9832 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageReceiver.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageReceiver.java @@ -5,6 +5,7 @@ */ package MV3500Cohort2018JulySeptember.FinalProject.LoeffelmanSeverson; + import edu.nps.moves.dis.CommentPdu; import edu.nps.moves.dis.EntityID; import edu.nps.moves.dis.EntityStatePdu; @@ -59,6 +60,7 @@ public class LoeffelmanSeversonDISImageReceiver { 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 @@ -72,7 +74,11 @@ public class LoeffelmanSeversonDISImageReceiver { 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); @@ -80,13 +86,19 @@ public class LoeffelmanSeversonDISImageReceiver { 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)); diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageSender.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageSender.java index ac4fbc8a02aa194ad9ee3600c726556612223ef1..a6b0f0d438d644d99cd5c65f9688dc2ec7a384fc 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageSender.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageSender.java @@ -108,17 +108,24 @@ public class LoeffelmanSeversonDISImageSender { 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]; @@ -127,10 +134,13 @@ public class LoeffelmanSeversonDISImageSender { 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; diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/LoeffelmanSeverson/Networks_Presentation.pptx b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/LoeffelmanSeverson/Networks_Presentation.pptx new file mode 100644 index 0000000000000000000000000000000000000000..36d9faa83e1b54412a11d65882e48720eacfb537 Binary files /dev/null and b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/LoeffelmanSeverson/Networks_Presentation.pptx differ