2

I have written a basic code to multicast UDP packets from a windows machine in java using this link. The receivers are several android phones, which run the receiver code given in the same link.

Here is the sender code:

int mcPort = 4446;
String mcIPStr = "225.4.5.6";

InetAddress group = InetAddress.getByName(mcIPStr);
DatagramSocket udpSocket = new DatagramSocket();
byte[] c = "SENT".getBytes();
DatagramPacket packet = new DatagramPacket(c, c.length, group, mcPort);
udpSocket.send(packet);
udpSocket.close();

Here is the receiver code:

int mcPort = 4446;
MulticastSocket mcSocket = new MulticastSocket(mcPort);
InetAddress group = InetAddress.getByName("225.4.5.6");
mcSocket.joinGroup(group);
DatagramPacket packet = new DatagramPacket(new byte[PACKET_SIZE],PACKET_SIZE);

mcSocket.receive(packet);

byte[] data = packet.getData();
String msg = new String(data);
System.out.println("message:"+msg);

When the windows machine is connected to the same wifi as the receiver nodes, the packets are received correctly. But I want to achieve the same functionality without the presence of an external wifi.

So I configured my windows machine to act as an access point using this link. The nodes are now connected to this AP. According to my understanding, the nodes should receive the packets now, but they don't!

What is it that I am missing?

vishalaksh
  • 2,054
  • 5
  • 27
  • 45

1 Answers1

1

Argh, such a pain. Multicast routing is subtle.

PCs running as AP is an exotic use case for most Wifi drivers. Some Wifi drivers only provide limited functionality in AP mode. Maybe your driver does not support multicast at all, or maybe it just fails to set up a default route for multicast.

Things you can check and try:

  • Are you sending the multicast packets over the correct network interface? The default network interface might no longer be the correct one when you are in AP mode. I cannot see in your sender code where you explicitly bind to a network adapter. Confusingly, this is usually done by IP-Address on Windows (and also on Linux), although there are other (non standard) alternatives.

  • Try to put the sender onto a different Windows PC and connect it also to the Windows PC running as AP. Does it work now? Then just the local routing of multicast packets is messed up.

  • What does Wireshark say on the local loopback device? (You must install npcap to even get a loopback device, but this is very useful to diagnose such problems, to see what goes on locally.)

  • What does a local receive (running on the AP) receive?

Johannes Overmann
  • 4,914
  • 22
  • 38