diff --git a/src/edu/nps/moves/dis7/examples/EspduSender.java b/src/edu/nps/moves/dis7/examples/EspduSender.java index da3de0fc93fc019f6b43bafbdfe44191a2142c7c..096644f9296479782d5399a01bb9096884426bd8 100644 --- a/src/edu/nps/moves/dis7/examples/EspduSender.java +++ b/src/edu/nps/moves/dis7/examples/EspduSender.java @@ -69,6 +69,7 @@ public class EspduSender // Network mode: unicast, multicast, broadcast String networkModeString = systemProperties.getProperty("networkMode"); // unicast or multicast or broadcast + InetSocketAddress group = null; // Set up a socket to send information try { @@ -76,7 +77,7 @@ public class EspduSender if (portString != null) port = Integer.parseInt(portString); - socket = new MulticastSocket(port); + socket = new MulticastSocket(); // Where we send packets to, the destination IP address if (destinationIpString != null) { @@ -96,7 +97,7 @@ public class EspduSender throw new RuntimeException("Sending to multicast address, but destination address " + destinationIp.toString() + " is not multicast"); } - InetSocketAddress group = new InetSocketAddress(destinationIp, port); + group = new InetSocketAddress(destinationIp, port); socket.joinGroup(group, DisThreadedNetIF.findIpv4Interface()); } } // end networkModeString @@ -232,10 +233,10 @@ public class EspduSender for (InetAddress broadcast : broadcastAddresses) { System.out.println("Sending broadcast datagram packet to " + broadcast); - packet = new DatagramPacket(data, data.length, broadcast, DisThreadedNetIF.DEFAULT_DIS_PORT); + packet = new DatagramPacket(data, data.length, broadcast, port); socket.send(packet); // TODO experiment with these! 8) - packet = new DatagramPacket(fireArray, fireArray.length, broadcast, DisThreadedNetIF.DEFAULT_DIS_PORT); // alternate + packet = new DatagramPacket(fireArray, fireArray.length, broadcast, port); // alternate socket.send(packet); } diff --git a/src/edu/nps/moves/dis7/examples/EspduSenderNIO.java b/src/edu/nps/moves/dis7/examples/EspduSenderNIO.java index 283c6adc2c0dcc8b6679b3fd3789c0cbdc5c1701..e577db84c039f957758169e935b8002cf8c4da48 100644 --- a/src/edu/nps/moves/dis7/examples/EspduSenderNIO.java +++ b/src/edu/nps/moves/dis7/examples/EspduSenderNIO.java @@ -42,7 +42,7 @@ public class EspduSenderNIO eid.setEntityID((short) 2); try { - socket = new MulticastSocket(DisThreadedNetIF.DEFAULT_DIS_PORT); + socket = new MulticastSocket(); maddr = InetAddress.getByName(DisThreadedNetIF.DEFAULT_MCAST_GROUP); group = new InetSocketAddress(maddr, DisThreadedNetIF.DEFAULT_DIS_PORT); socket.joinGroup(group, DisThreadedNetIF.findIpv4Interface()); @@ -51,7 +51,7 @@ public class EspduSenderNIO EulerAngles orientation; float psi; byte[] data = new byte[144]; - DatagramPacket packet = new DatagramPacket(data, data.length, maddr, DisThreadedNetIF.DEFAULT_DIS_PORT); + DatagramPacket packet = new DatagramPacket(data, data.length, group); while (true) { for (int idx = 0; idx < 100; idx++) { diff --git a/src/edu/nps/moves/dis7/examples/PduSender.java b/src/edu/nps/moves/dis7/examples/PduSender.java index dfe38c47dd38708fc0c7efb93ceceff0433f3f63..e59e18bea02e8438d5c0a150bed89c5ab1fccd68 100644 --- a/src/edu/nps/moves/dis7/examples/PduSender.java +++ b/src/edu/nps/moves/dis7/examples/PduSender.java @@ -41,7 +41,7 @@ public class PduSender } } catch (UnknownHostException e) { - System.out.println("Unable to open socket: " + e); + System.err.println("Unable to open socket: " + e); } } @@ -289,9 +289,8 @@ public class PduSender // Send the PDUs we created DatagramPacket packet; - InetAddress localMulticastAddress = InetAddress.getByName(DisThreadedNetIF.DEFAULT_MCAST_GROUP); - MulticastSocket socket = new MulticastSocket(port); - InetSocketAddress group = new InetSocketAddress(localMulticastAddress, port); + MulticastSocket socket = new MulticastSocket(); + InetSocketAddress group = new InetSocketAddress(multicastAddress, port); socket.joinGroup(group, DisThreadedNetIF.findIpv4Interface()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -303,7 +302,7 @@ public class PduSender pdu.marshal(dos); buffer = baos.toByteArray(); - packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, port); + packet = new DatagramPacket(buffer, buffer.length, group); socket.send(packet); System.out.println("Sent PDU of type " + pdu.getClass().getSimpleName() + " ("+pdu.getPduType().getValue()+")"); baos.reset(); diff --git a/src/edu/nps/moves/dis7/utilities/DisThreadedNetIF.java b/src/edu/nps/moves/dis7/utilities/DisThreadedNetIF.java index 81cf58fd21a0af57024b5fba398721385f1b4771..e71139f9d56c9bca0d27daf75a95847b938f80d3 100644 --- a/src/edu/nps/moves/dis7/utilities/DisThreadedNetIF.java +++ b/src/edu/nps/moves/dis7/utilities/DisThreadedNetIF.java @@ -270,7 +270,7 @@ public class DisThreadedNetIF // The capacity could go up to MAX_DIS_PDU_SIZE, but this should be good for now ByteArrayOutputStream baos = new ByteArrayOutputStream(MAX_TRANSMISSION_UNIT_SIZE); DataOutputStream dos = new DataOutputStream(baos); - DatagramPacket packet = new DatagramPacket(baos.toByteArray(), baos.size(), maddr, disPort); + DatagramPacket packet = new DatagramPacket(baos.toByteArray(), baos.size(), group); while (!killed) { // keep trying on error try {