Skip to content
Snippets Groups Projects
Commit 153fa062 authored by John Furr's avatar John Furr
Browse files

Added project file

parent f6d1b97b
No related branches found
No related tags found
No related merge requests found
Showing
with 205 additions and 0 deletions
...@@ -45,3 +45,4 @@ ...@@ -45,3 +45,4 @@
/projects/UdpExample1/UdpReceiver/nbproject/private/ /projects/UdpExample1/UdpReceiver/nbproject/private/
/projects/UdpExample1/UdpSender/build/ /projects/UdpExample1/UdpSender/build/
/projects/UdpExample1/UdpSender/nbproject/private/ /projects/UdpExample1/UdpSender/nbproject/private/
/CourseExamples/dist/
\ No newline at end of file
package MV3500Cohort2018JulySeptember.FinalProject.FriscoFurrProject;
import java.io.*;
import java.net.*;
import java.util.*;
import edu.nps.moves.dis.*;
import edu.nps.moves.disenum.*;
import edu.nps.moves.examples.ClassNameComparator;
/**
* 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.
* Adapted from OpenDIS library example package edu.nps.moves.examples
*
* @author DMcG
* @version $Id:$
*/
public class FriscoFurrPduSender
{
/** Default multicast group address we send on. */
public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3";
/** Default multicast port used, matches Wireshark DIS capture default */
public static final int DEFAULT_MULTICAST_PORT = 3000;
private int port;
InetAddress multicastAddress;
public FriscoFurrPduSender(int port, String multicast) {
try
{
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 {
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();
EntityStatePdu espdu = (EntityStatePdu) aPdu;
Marking marking = new Marking();
marking.setCharactersString("PduSender");
espdu.setMarking(marking);
Vector3Double espduLocation = new Vector3Double();
espduLocation.setX(1.0);
espduLocation.setY(2.0);
espduLocation.setZ(3.0);
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 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) {
FriscoFurrPduSender sender = new FriscoFurrPduSender(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);
FriscoFurrPduSender sender = new FriscoFurrPduSender(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS);
sender.run();
}
}
}
#Wed, 22 Aug 2018 09:40:08 -0700
E\:\\Documents\\NPS\\MV3500_Internetwork_Communications\\NetworkedGraphicsMV3500\\projects\\MulticastExample\\MulticastReceiver=
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
</project-private>
#Mon, 20 Aug 2018 09:06:48 -0700
E\:\\Documents\\NPS\\MV3500_Internetwork_Communications\\NetworkedGraphicsMV3500\\projects\\TcpExample3\\Client\\TcpClient=
File added
#Mon, 20 Aug 2018 09:06:34 -0700
E\:\\Documents\\NPS\\MV3500_Internetwork_Communications\\NetworkedGraphicsMV3500\\projects\\TcpExample3\\Server\\TcpServer=
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment