diff --git a/src/edu/nps/moves/dis7/examples/EspduReceiverNIO.java b/src/edu/nps/moves/dis7/examples/EspduReceiverNIO.java index 5fa310440a0deadd56221353eca2674b32681ddd..6fecef94c55d012405ed5a68d8f54215c3117b36 100644 --- a/src/edu/nps/moves/dis7/examples/EspduReceiverNIO.java +++ b/src/edu/nps/moves/dis7/examples/EspduReceiverNIO.java @@ -5,10 +5,12 @@ package edu.nps.moves.dis7.examples; import edu.nps.moves.dis7.Pdu; +import edu.nps.moves.dis7.utilities.DisThreadedNetIF; import edu.nps.moves.dis7.utilities.PduFactory; import java.io.IOException; import java.net.DatagramPacket; import java.net.InetAddress; +import java.net.InetSocketAddress; import java.net.MulticastSocket; import java.nio.ByteBuffer; @@ -31,7 +33,8 @@ public class EspduReceiverNIO public static void main(String args[]) { MulticastSocket socket; - InetAddress address; + InetAddress maddr; + InetSocketAddress group; PduFactory pduFactory = new PduFactory(); byte buffer[] = new byte[MAX_PDU_SIZE]; DatagramPacket packet = new DatagramPacket(buffer, buffer.length); @@ -39,11 +42,12 @@ public class EspduReceiverNIO Pdu pdu; try { + // Specify the socket to receive data - socket = new MulticastSocket(EspduSender.DIS_DESTINATION_PORT); - address = InetAddress.getByName(EspduSender.DEFAULT_MULTICAST_GROUP); - // TODO fix deprecation by adding NetworkInterface (hopefully DisThreadedNetworkInterface) - socket.joinGroup(address); + socket = new MulticastSocket(EspduSenderNIO.PORT); + maddr = InetAddress.getByName(EspduSenderNIO.MULTICAST_GROUP); + group = new InetSocketAddress(maddr, EspduSenderNIO.PORT); + socket.joinGroup(group, DisThreadedNetIF.findIp4Interface()); // Loop infinitely, receiving datagrams while (true) { diff --git a/src/edu/nps/moves/dis7/examples/EspduSenderNIO.java b/src/edu/nps/moves/dis7/examples/EspduSenderNIO.java index 2a293d021423340d63ec4fbfecced14e00f9f346..9fea77c50f9963d3a2ea2c5c14ec6ad13372fbeb 100644 --- a/src/edu/nps/moves/dis7/examples/EspduSenderNIO.java +++ b/src/edu/nps/moves/dis7/examples/EspduSenderNIO.java @@ -8,8 +8,10 @@ import edu.nps.moves.dis7.EntityID; import edu.nps.moves.dis7.EntityStatePdu; import edu.nps.moves.dis7.EulerAngles; import edu.nps.moves.dis7.Vector3Double; +import edu.nps.moves.dis7.utilities.DisThreadedNetIF; import java.net.DatagramPacket; import java.net.InetAddress; +import java.net.InetSocketAddress; import java.net.MulticastSocket; /** @@ -35,7 +37,8 @@ public class EspduSenderNIO public static void main(String args[]) { MulticastSocket socket; - InetAddress address; + InetAddress maddr; + InetSocketAddress group; EntityStatePdu espdu = new EntityStatePdu(); espdu.setExerciseID((byte) 0); @@ -50,14 +53,15 @@ public class EspduSenderNIO try { socket = new MulticastSocket(PORT); - address = InetAddress.getByName(MULTICAST_GROUP); - socket.joinGroup(address); + maddr = InetAddress.getByName(MULTICAST_GROUP); + group = new InetSocketAddress(maddr, PORT); + socket.joinGroup(group, DisThreadedNetIF.findIp4Interface()); Vector3Double location; EulerAngles orientation; float psi; byte[] data = new byte[144]; - DatagramPacket packet = new DatagramPacket(data, data.length, address, PORT); + DatagramPacket packet = new DatagramPacket(data, data.length, maddr, PORT); while (true) { for (int idx = 0; idx < 100; idx++) {