4

I am learning and trying to understand how Multicast is implemented in Java. I had developed a small program following the example given at http://www.nmsl.cs.ucsb.edu/MulticastSocketsBook/#javaexamples and it did do multicast of datagram (UDP) packets to multiple clients on same host.

However when I tried to run clients on different machines (within same LAN (i.e. my home WiFi) no packets got received at client end. I made sure that my router's firewall was disabled as well as all other machines had a port open.

Thinking my program could have some error, I took the examples, compiled them and run server and client on different machines but same result (no packet delivery to different machines). I even tried running client on Ubuntu (within VirtualBox with Bridge Adapter) but no luck.

After going through SO, I came across Java Multicast Time To Live is always 0 explaining the problem with TTL header in Java multicast. So I applied the suggestion provided in that question's answer but still same problem. I tracked the packets with WireShark and verified that TTL had indeed value 5 (I set it to 5 to widen the probability !)

I am not sure where I am doing wrong. I would really appreciate if you can point me into right direction.

P.S. : I had used multicast addresses like 235.1.1.1 / 239.255.211.111 and port 4466 (this port I kept open in firewall of all machines for inbound + outbound n/w)

Community
  • 1
  • 1
jatanp
  • 3,982
  • 4
  • 40
  • 46
  • Tell me whether your local host is `multi-homed` or not; i.e having more than one network interface. If you do, then you need to use the third constructor of `DatagramSocket` class where you need to supply local port and local binding IP address of your preferred network interface – ecle Dec 12 '11 at 08:17
  • Interesting, I'm having the very same problems you are having in my Java project right this second! I'm not sure of a solution myself... – Oliver Spryn Dec 12 '11 at 08:28
  • 3
    If you are in `multi-homed` setup and you are using `MulticastSocket` class, then use `setInterface(inetAddress)` to set the binding IP address of your preferred network interface – ecle Dec 12 '11 at 08:30
  • If whatever I've said still fails, then my suspect is that your LAN router doesn't broadcast multicast [http://stackoverflow.com/questions/2656590/how-do-i-make-my-multicast-program-work-between-computers-on-different-networks](http://stackoverflow.com/questions/2656590/how-do-i-make-my-multicast-program-work-between-computers-on-different-networks) – ecle Dec 12 '11 at 08:45
  • 1
    @eee you are great. My socket was somehow getting connected to VirtualBox n/w adapter instead of my Wifi adapter ! I am not sure why does it happen like that ! Please post your comment as answer and I will mark it as accepted answer. Thanks so much. – jatanp Dec 12 '11 at 17:44
  • can you explain this with the setInterface(inetAddress) on the multicastSocket? how do I get my network interface inetAddress? @jatanp – dumazy Oct 18 '12 at 16:30
  • @dumazy on Windows you may run ipconfig or ifconfig on Linux to know the available interfaces and their assigned / allocated IPs. If you have DHCP then probably you can scan the available IPs using following snippet, for(InetAddress ia : InetAddress.getAllByName(InetAddress.getLocalHost().getHostName())) { System.out.println(ia); } Try to match the required subnet to choose the network interface address (i.e. ia) in loop and bind to that interface. – jatanp Jan 16 '13 at 17:27

0 Answers0