One of the elements not clearly stated if reading the java multicast documentation and examples found on the net is that if you create a multicast receiver this will NOT listed to all available interfaces. Instead one must specify the desired interface because otherwise the MulticastSocket will only listen to the first active (default?) interface. Here is an example of code which specifies exactly the interface to listen to:

import java.net.DatagramPacket;<br></br>import java.net.InetAddress;<br></br>import java.net.MulticastSocket;<br></br><br></br>...<br></br><br></br>MulticastSocket s = new MulticastSocket(port);<br></br>#clearly specify the desired interface to listen<br></br>s.setInterface(InetAddress.getByName(interfaceIP));<br></br>#<br></br>s.joinGroup(InetAddress.getByName(group));<br></br><br></br>byte buf[] = new byte[1024];<br></br>DatagramPacket pack = new DatagramPacket(buf, buf.length);<br></br><br></br>s.receive(pack);<br></br><br></br>...<br></br>

If you don’t do that it is possible in cases where multiple interfaces are present to find yourself never receiving the multicast packets. Here is an useful command on linux to show the multicast packets

 tcpdump -i eth1 -n -v udp and ip multicast

One possible solution would be to listen on all interfaces, here is some code (available since java 1.4) to show the interfaces:

Enumeration ints = NetworkInterface.getNetworkInterfaces();<br></br>while (ints.hasMoreElements()) {<br></br>	NetworkInterface ni = (NetworkInterface) ints.nextElement();<br></br>	Enumeration ips = ni.getInetAddresses();<br></br>	System.out.println(ni.getName());<br></br>	while (ips.hasMoreElements()) {<br></br>		InetAddress ip = (InetAddress) ips.nextElement();<br></br>		System.out.println(ip.getHostAddress());<br></br>	}<br></br>}<br></br>