This discussion is archived
5 Replies Latest reply: Nov 11, 2012 12:43 PM by 973534 RSS

Unable to receive multicast on a multi network interface host

973534 Newbie
Currently Being Moderated
Can anyone please help?
I am not able to receive multicast on a multi network interface host.
This is the code:

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

The funny thing is that when I start this code, Wireshark detects IGMP join on the correct network interface caused by joinGroup call, followed by constant UDP traffic on correct port which I aim to receive and finally I see correct IGMP leave caused by leaveGroup call and the UDP traffic stops.
I just don't receive anything on socket.receive call.
I am trying to figure this one out for days now. Pls help someone :)

P.S. I suspected security, but System.getSecurityManager() call returns null.
P.P.S. I also tried implementing this with NIO, but with same result.
  • 1. Re: Unable to receive multicast on a multi network interface host
    jtahlborn Expert
    Currently Being Moderated
    what OS are you on? is your network interface in promiscuous mode? not a super expert on this stuff but i believe if your network interface is not configured in a certain way, it will not receive its own multicast traffic.
  • 2. Re: Unable to receive multicast on a multi network interface host
    EJP Guru
    Currently Being Moderated
    InetSocketAddress group = new InetSocketAddress("224.10.20.30", 12345);
    NetworkInterface iface = NetworkInterface.getByName("eth3");
    MulticastSocket socket = new MulticastSocket();
    MulticastSocket socket = new MulticastSocket(12345);

    You're not listening at the correct port.
  • 3. Re: Unable to receive multicast on a multi network interface host
    EJP Guru
    Currently Being Moderated
    what OS are you on?
    Irrelevant. This is Java.
    is your network interface in promiscuous mode?
    Irrelevant.
    not a super expert on this stuff but i believe if your network interface is not configured in a certain way, it will not receive its own multicast traffic.
    Irrelevant. There is no evidence that he is sending to himself.
  • 4. Re: Unable to receive multicast on a multi network interface host
    jtahlborn Expert
    Currently Being Moderated
    EJP wrote:
    what OS are you on?
    Irrelevant. This is Java.
    is your network interface in promiscuous mode?
    Irrelevant.
    yes, promiscuous mode was the wrong term. i was looking for multicast loopback. i seem to remember having an issue with this back in the day (being disabled by default), and it was OS specific, hence my initial comment. Java runs on an OS, so occasionally the OS is relevant.
    not a super expert on this stuff but i believe if your network interface is not configured in a certain way, it will not receive its own multicast traffic.
    Irrelevant. There is no evidence that he is sending to himself.
    valid point. i was assuming both test endpoints were being run on the same host, but it does not actually say that anywhere in the OP.
  • 5. Re: Unable to receive multicast on a multi network interface host
    973534 Newbie
    Currently Being Moderated
    public class LegacyMulticast {
    public static void main(String[] args) throws IOException {
    InetSocketAddress group = new InetSocketAddress("224.10.20.30", 12345);
    NetworkInterface iface = NetworkInterface.getByName("eth3");
    MulticastSocket socket = new MulticastSocket(12345);
    socket.setSoTimeout(5000);
    socket.joinGroup(group , iface);
    byte[] b = new byte[4096];
    DatagramPacket datagram = new DatagramPacket(b, b.length);
    try {
    socket.receive(datagram);
    System.out.println("Success");
    }
    catch (SocketTimeoutException ste) {
    System.out.println("Failure");
    }
    socket.leaveGroup(group, iface);
    }
    }

    This is still not working.
    The multicast is coming from the network (not localhost), OS is Windows 7.
    When I start a multicast stream localy via VLC application on this same group and port, I receive the traffic in this Java application OK.
    Once again, Wireshark detects IGMP join and leave and multicast traffic flow on eth3 network interface initiated by the Java application, but it just doesn't see the UDP datagrams.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points