0

I've spent some time learning about UDP connections, particularly with Multicast Sockets in Java.

I was able to make a simple Multicast Socket "group chat" on my local network, but I've since been trying to expand this to work beyond my local network.

In attempts to achieve this, I port-forwarded a Class D IP address on my router in order to allow other people to access my Multicast group from outside my network.

However, when trying to connect to my "group chat" via my public IP and specified port (during the port-forwarding), I would receive the following error message...

Exception in thread "main" java.net.SocketException: Not a multicast address
at java.net.MulticastSocket.joinGroup(MulticastSocket.java:310)
...

This error makes some sense, given that my public IP isn't a class D address. But since I port-forwarded a multicast address to the specified port on my router, shouldn't this problem not occur?

Here's the relevant part of my code...

InetAddress group = InetAddress.getByName("192.___.___.___"); // my public IP
MulticastSocket socket = new MulticastSocket(1234); // the port-forwarded port
socket.joinGroup(group);

Where had I gone wrong here, and how could I get to fixing this issue?

Dan
  • 324
  • 1
  • 3
  • 13
  • Multicast routing is very different from unicast routing. Multicast is confined to a single LAN, unless all the routers in the path are configured with multicast routing, which is why you cannot multicast on the Internet. Port forwarding is for unicast NAPT, not multicast. You can use multicast between sites if you tunnel it across the Internet, but not all tunnel protocols support multicast. – Ron Maupin Jan 02 '20 at 08:00

1 Answers1

0

A multicast address is between 224.0.0.0 - 239.255.255.255 with different sub-ranges within for different scenarios. More here: https://en.wikipedia.org/wiki/Multicast_address

So by attempting to join a group at 192.x.y.z, that's an invalid multicast address. That's why you get the exception thrown.

I could be mistaken, I doubt most consumer/home NAT, much less ISPs support multicast traffic. (Begs the questions - whatever happened to the MBONE - I thought that would have taken off and been the solution for everything.)

It sounds like what you need is a proxy program that intercepts multicast traffic and tunnels it to a proxy on a different network running the same code. The proxy in turn, takes the tunnelled packet and redirects back to a multicast\broadcast group.

You might have better luck with broadcast sockets instead of multicast.

selbie
  • 100,020
  • 15
  • 103
  • 173
  • `It sounds like what you need is a proxy program that intercepts multicast traffic and tunnels it to a proxy on a different network running the same code.` the same problem would likely arise. android would still choke on the address due to it not falling withing the standard range. very annoying issue. – omikes Mar 12 '20 at 18:39