1 Reply Latest reply on Nov 14, 2012 10:36 PM by EJP

    Unable to receive multicast using NIO

      or using MulticastSocket also.

      I am trying to receive mutlicast group on a multi-NIC Windows 7 host on iface eth3 in Java.
      Multicast is coming from the network.
      I tried using NIO and MulticastSocket but it doesn't work.
      Using netwotk analyzer I see both implementations invoke IGMP join and leave on eth3 and the UDP traffic is present on eth3 UDP port 12345 between join and leave.
      Java just doesn't see the packets.

      This is the NIO code I used:

      public class NioMulticasting {

      public static void main(String[] args) {
      try {
      System.out.println("Security manager = " + System.getSecurityManager());
      NetworkInterface interf = NetworkInterface.getByName("eth3");
      InetAddress group = InetAddress.getByName("");

      DatagramChannel dc = DatagramChannel.open(StandardProtocolFamily.INET)
      .setOption(StandardSocketOptions.SO_REUSEADDR, true)
      .bind(new InetSocketAddress(12345))
      .setOption(StandardSocketOptions.IP_MULTICAST_IF, interf);
      Selector selector = Selector.open();
      dc.register (selector, SelectionKey.OP_READ);

      MembershipKey key = dc.join(group, interf);
      System.out.println("Membership on iface " + interf.getName() + " valid : " + key.isValid());

      int result = selector.select(10000);
      System.out.println("Select result " + result);
      catch (Exception ee) {

      Results in:
      Security manager = null
      Membership on iface eth3 valid : true
      Select result 0
      BUILD SUCCESSFUL (total time: 10 seconds)


      public class LegacyMulticast {
      public static void main(String[] args) throws IOException {  
      System.out.println("Security manager = " + System.getSecurityManager());
      InetSocketAddress group = new InetSocketAddress("", 12345);
      NetworkInterface iface = NetworkInterface.getByName("eth3");
      MulticastSocket socket = new MulticastSocket(12345);
      socket.joinGroup(group , iface);
      byte[] b = new byte[4096];
      DatagramPacket datagram = new DatagramPacket(b, b.length);
      try {
      catch (SocketTimeoutException ste) {
      socket.leaveGroup(group, iface);

      results in:
      Security manager = null
      BUILD SUCCESSFUL (total time: 10 seconds)

      I am not able to figure this one out...