diff --git a/examples/src/OpenDis7Examples/EspduReceiver.java b/examples/src/OpenDis7Examples/EspduReceiver.java index 54253c20f8e447c74f6bec3412518efdfd4f4d9f..f99b0f03556be9aadacaf281edad7ae367bc1837 100755 --- a/examples/src/OpenDis7Examples/EspduReceiver.java +++ b/examples/src/OpenDis7Examples/EspduReceiver.java @@ -26,15 +26,20 @@ public class EspduReceiver /** Default multicast port used, matches Wireshark DIS capture default */ public static final int DEFAULT_MULTICAST_PORT = EspduSender.DEFAULT_MULTICAST_PORT; + + /** + * Output prefix to identify this class + */ + private final static String TRACE_PREFIX = "[" + EspduReceiver.class.getName() + "] "; public static void main(String args[]) { - System.out.println("OpenDis7Examples.EspduReceiver started..."); + System.out.println(TRACE_PREFIX + "started..."); MulticastSocket socket; - DatagramPacket packet; - InetAddress address; - PduFactory pduFactory = new PduFactory(); + DatagramPacket packet; + InetAddress address; + PduFactory pduFactory = new PduFactory(); int pduCount = 0; try { @@ -43,10 +48,11 @@ public class EspduReceiver // socket.setBroadcast(true); address = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); - socket.joinGroup(address); +////// socket.joinGroup(address); // TODO not needed! - System.out.println("OpenDis7Examples.EspduReceiver: listening for PDU packets on " + address.getHostAddress() + " port " + DEFAULT_MULTICAST_PORT); - + System.out.println(TRACE_PREFIX + "listening for PDU packets on " + address.getHostAddress() + " port " + DEFAULT_MULTICAST_PORT); + System.out.println("==============="); + while (true) // Loop infinitely, receiving datagrams { byte buffer[] = new byte[MAX_PDU_SIZE]; @@ -66,7 +72,6 @@ public class EspduReceiver + ". received PDU type " + aPdu.getPduType().getValue() + "=" + aPdu.getPduType().name() + " " + aPdu.getClass().getName(); if (aPdu instanceof EntityStatePdu) { - System.out.println("==============="); System.out.println(receiptMessage); EntityID entityID = ((EntityStatePdu)aPdu).getEntityID(); Vector3Double position = ((EntityStatePdu)aPdu).getEntityLocation(); @@ -78,20 +83,20 @@ public class EspduReceiver System.out.println(receiptMessage); Vector3Double position = ((FirePdu)aPdu).getLocationInWorldCoordinates(); System.out.println(" FirePdu locationInWorldCoordinates: [" + position.getX() + ", " + position.getY() + ", " + position.getZ() + "]"); - + System.out.println("==============="); } else { System.out.println(receiptMessage); } - } - } // end while + } // end of bundle loop + } // end of while loop } // end try block - catch (IOException e) + catch (IOException ioe) { - System.out.println("Problem with OpenDis7Examples.EspduReceiver, see exception trace:"); - System.out.println(e); + System.out.println(TRACE_PREFIX + "Problem with input/output, see exception trace:"); + System.out.println(ioe); } - System.out.println("OpenDis7Examples.EspduReceiver complete."); + System.out.println(TRACE_PREFIX + "complete."); } // end main } // end class