diff --git a/src/edu/nps/moves/dis7/examples/EspduReceiverNIO.java b/src/edu/nps/moves/dis7/examples/EspduReceiverNIO.java index a605572f4cdea3b66a86a8a07fc81d5e22eb13ff..307e80d2b45b5e33019363c1748a94cd0c7a30f3 100644 --- a/src/edu/nps/moves/dis7/examples/EspduReceiverNIO.java +++ b/src/edu/nps/moves/dis7/examples/EspduReceiverNIO.java @@ -23,37 +23,36 @@ public class EspduReceiverNIO { public static void main(String args[]) { - MulticastSocket socket; - InetAddress maddr; + MulticastSocket socket; + InetAddress multicastAddress; InetSocketAddress group; - PduFactory pduFactory = new PduFactory(); - byte buffer[] = new byte[DisThreadedNetworkInterface.MAX_DIS_PDU_SIZE]; - DatagramPacket packet = new DatagramPacket(buffer, buffer.length); + PduFactory pduFactory = new PduFactory(); + byte buffer[] = new byte[DisThreadedNetworkInterface.MAX_DIS_PDU_SIZE]; + DatagramPacket packet = new DatagramPacket(buffer, buffer.length); Pdu pdu; int pduCounter = 0; - try { - + try + { // Specify the socket to receive data - socket = new MulticastSocket(DisThreadedNetworkInterface.DEFAULT_DIS_PORT); - maddr = InetAddress.getByName(DisThreadedNetworkInterface.DEFAULT_MULTICAST_ADDRESS); - group = new InetSocketAddress(maddr, DisThreadedNetworkInterface.DEFAULT_DIS_PORT); - socket.joinGroup(group, DisThreadedNetworkInterface.findIpv4Interface()); + socket = new MulticastSocket(DisThreadedNetworkInterface.DEFAULT_DIS_PORT); + multicastAddress = InetAddress.getByName(DisThreadedNetworkInterface.DEFAULT_MULTICAST_ADDRESS); + group = new InetSocketAddress(multicastAddress, DisThreadedNetworkInterface.DEFAULT_DIS_PORT); + socket.joinGroup(group, DisThreadedNetworkInterface.findIpv4Interface()); // picks best candidate - // Loop infinitely, receiving datagrams - while (true) { - + while (true) // Loop indefinitely, receiving datagrams + { socket.receive(packet); pdu = pduFactory.createPdu(packet.getData()); pduCounter++; - System.out.println(pduCounter + ". got PDU of type: " + pdu.getClass().getSimpleName()); - + } // end while - } // End try // End try - catch (IOException e) { + } // End try + catch (IOException e) + { System.err.println(e); } diff --git a/src/edu/nps/moves/dis7/examples/EspduSenderNIO.java b/src/edu/nps/moves/dis7/examples/EspduSenderNIO.java index 9fbab2d8bfc8ce767eba88794b9fd81e0928ee4e..b986118ad89aeba7809203ee6e36758164232d84 100644 --- a/src/edu/nps/moves/dis7/examples/EspduSenderNIO.java +++ b/src/edu/nps/moves/dis7/examples/EspduSenderNIO.java @@ -26,26 +26,26 @@ public class EspduSenderNIO { public static void main(String args[]) { - MulticastSocket socket; - InetAddress maddr; + MulticastSocket socket; + InetAddress multicastAddress; InetSocketAddress group; - EntityStatePdu espdu = new EntityStatePdu(); + EntityStatePdu espdu = new EntityStatePdu(); espdu.setExerciseID((byte) 0); - // The EID is the unique identifier for objects in the world. This - // EID should match up with the ID for the object specified in the - // VMRL/x3d world. + // The EID is the unique identifier for objects in the world. This EID + // should match up with the ID for the object specified in the VMRL/x3d world. EntityID eid = espdu.getEntityID(); - eid.setSiteID((short) 1); // 0 is apparently not a valid site number + eid.setSiteID ((short) 1); // 0 is apparently not a valid site number eid.setApplicationID((short) 1); - eid.setEntityID((short) 2); + eid.setEntityID ((short) 2); - try { - socket = new MulticastSocket(); - maddr = InetAddress.getByName(DisThreadedNetworkInterface.DEFAULT_MULTICAST_ADDRESS); - group = new InetSocketAddress(maddr, DisThreadedNetworkInterface.DEFAULT_DIS_PORT); - socket.joinGroup(group, DisThreadedNetworkInterface.findIpv4Interface()); + try + { + socket = new MulticastSocket(); + multicastAddress = InetAddress.getByName(DisThreadedNetworkInterface.DEFAULT_MULTICAST_ADDRESS); + group = new InetSocketAddress(multicastAddress, DisThreadedNetworkInterface.DEFAULT_DIS_PORT); + socket.joinGroup(group, DisThreadedNetworkInterface.findIpv4Interface()); // picks best candidate Vector3Double location; EulerAngles orientation; @@ -53,8 +53,10 @@ public class EspduSenderNIO byte[] data = new byte[144]; DatagramPacket packet = new DatagramPacket(data, data.length, group); - while (true) { - for (int idx = 0; idx < 100; idx++) { + while (true) + { + for (int idx = 0; idx < 100; idx++) + { // The timestamp should be monotonically increasing. Many implementations // discard packets that have earlier timestamps (assumption is that it // arrived out of order) or non-increasing timestamp (dupe packet). @@ -92,7 +94,8 @@ public class EspduSenderNIO } } } - catch (Exception e) { + catch (Exception e) + { System.err.println(e); } }