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?