Skip to content
Snippets Groups Projects
Commit 1b44ea97 authored by Brittokki's avatar Brittokki
Browse files

Merge origin/master

Conflicts:
	assignments/src/MV3500Cohort2020JulySeptember/homework4/WeissenbergerGoericke/TCPReceiverVPNBridge.java
	assignments/src/MV3500Cohort2020JulySeptember/homework4/WeissenbergerGoericke/TcpServerForFinal.java
	examples/src/HttpServletExamples/HttpWebPageSource.java
	examples/src/OpenDis7Examples/ExampleSimulationProgram.java
	examples/src/UdpMulticastExamples/UdpSender.java
	nbproject/nbjdk.properties
parent e7cd5313
No related branches found
No related tags found
No related merge requests found
package MV3500Cohort2020JulySeptember.homework4.White;
import MV3500Cohort2020JulySeptember.homework4.White.working.*;
import java.io.*;
import java.net.*;
import java.util.*;
import edu.nps.moves.dis7.pdus.*;
import edu.nps.moves.dis7.utilities.*;
/**
* Receives PDUs from GermanyEspduReceiverEspduVPNSender in IEEE DIS format.
*
* @date 09/05/2020
* @author Bernd/Stefan
* @version 0.1
*/
public class PDUReciever {
/**
* Max size of a PDU in binary format that we can receive. This is actually
* somewhat outdated--PDUs can be larger--but this is a reasonable starting
* point.
*/
public static final int MAX_PDU_SIZE = 8192;
/**
* Default port used, matches Wireshark DIS capture default
*/
public static final int DEFAULT_PORT = 2317;
public static final int SECOND_PORT = 3000;
public static final int THIRD_PORT = 2318;
/**
* Output prefix to identify this class
*/
private final static String TRACE_PREFIX = "[" + PDUReciever.class.getName() + "] ";
public static void main(String args[]) {
System.out.println(TRACE_PREFIX + "started...");
MulticastSocket socket1;
MulticastSocket socket2;
MulticastSocket socket3;
DatagramPacket packet;
DatagramPacket packet2;
DatagramPacket packet3;
PduFactory pduFactory = new PduFactory();
ArrayList<EntityID> knownEntities = new ArrayList<EntityID>();
int pduCount = 0;
try {
// Specify the socket to receive data
socket1 = new MulticastSocket(DEFAULT_PORT);
socket2 = new MulticastSocket(SECOND_PORT);
socket3 = new MulticastSocket(THIRD_PORT);
System.out.println(TRACE_PREFIX + "listening for PDU packets on port " + DEFAULT_PORT );//+ " " + SECOND_PORT + " " + THIRD_PORT);
System.out.println("====================================================");
while (true) // Loop infinitely, receiving datagrams
{
byte buffer[] = new byte[MAX_PDU_SIZE];
packet = new DatagramPacket(buffer, buffer.length);
socket1.receive(packet);
List<Pdu> pduBundle = pduFactory.getPdusFromBundle(packet.getData(), packet.getLength());
if (pduBundle.size() > 1) { // should be 1 for this project
System.out.println("Bundle size is " + pduBundle.size());
}
// end iterator loop through PDU bundle
for (Pdu aPdu : pduBundle) {
pduCount++;
String receiptMessage = String.format("%3s", pduCount) // right justify, 3 characters
+ ". received PDU type " + aPdu.getPduType().getValue() + "=" + aPdu.getPduType().name() + " " + aPdu.getClass().getName() + " from " + packet.getAddress();
if (aPdu instanceof EntityStatePdu) {
System.out.println(receiptMessage);
EntityID entityID = ((EntityStatePdu) aPdu).getEntityID();
Vector3Double position = ((EntityStatePdu) aPdu).getEntityLocation();
System.out.println(" entityID triplet: [" + entityID.getSiteID() + ", " + entityID.getApplicationID() + ", " + entityID.getEntityID() + "] ");
if (!knownEntities.contains(entityID)){
knownEntities.add(entityID);
EntityType entityType = ((EntityStatePdu) aPdu).getEntityType();
System.out.println(" New Entity: " +entityType.getEntityKind() + " "+ entityType.getDomain() + " "+ entityType.getCountry() + " "+ entityType.getCategory() + " "+ entityType.getSubCategory() + " "+ entityType.getSpecific() );
}
System.out.println(" Location in DIS coordinates: [" + position.getX() + ", " + position.getY() + ", " + position.getZ() + "]");
}
else if (aPdu instanceof FirePdu){
System.out.println(receiptMessage);
EntityID firingEntityID = ((FirePdu) aPdu).getFiringEntityID();
EntityID targetEntityID = ((FirePdu) aPdu).getTargetEntityID();
MunitionDescriptor munitionDescriptor = ((FirePdu) aPdu).getDescriptor();
System.out.println(" firingEntityID triplet: [" + firingEntityID.getSiteID() + ", " + firingEntityID.getApplicationID() + ", " + firingEntityID.getEntityID() + "] ");
System.out.println(" targetEntityID triplet: [" + targetEntityID.getSiteID() + ", " + targetEntityID.getApplicationID() + ", " + targetEntityID.getEntityID() + "] ");
System.out.println(" Munition Information: [" + munitionDescriptor.getMunitionType().getDomain() + "."+munitionDescriptor.getMunitionType().getCountry() + "." + munitionDescriptor.getMunitionType().getCategory() + "."+ munitionDescriptor.getMunitionType().getSubCategory() + "." + munitionDescriptor.getMunitionType().getSpecific() + "]");
}
else if (aPdu instanceof CommentReliablePdu){
System.out.println(receiptMessage);
ArrayList<VariableDatum> payloadList = (ArrayList)((CommentReliablePdu) aPdu).getVariableDatumRecords();
if (!payloadList.isEmpty())
System.out.print (" messages: ");
for (VariableDatum variableDatum : payloadList)
{
String nextComment = new String(variableDatum.getVariableDatumValue()); // convert byte[] to String
System.out.print (" \"" + nextComment + "\"");
System.out.println();
}
} //OTHER PDU TYPES
else {
System.out.println(receiptMessage);
}
} // end of bundle loop
} // end of while loop
} // end try block // end try block // end try block // end try block
catch (IOException ioe) {
System.out.println(TRACE_PREFIX + "Problem with input/output, see exception trace:");
System.out.println(ioe);
}
System.out.println(TRACE_PREFIX + "complete.");
} // end main
} // end class
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