I need to send and receive in multicast.
I posted the question on StackOverflow Forum for checking my code: https://stackoverflow.com/questions/50131973/java-multicast-socket-doesnt-receive-anything-on-windows
I tried my code on Ubuntu and it works perfectly.
Now I'm doing experiments on Windows 10. I use multicast socket to send and receive DatagramPacket. If the InetAddress of datagram is "230.0.0.1" for multicasting, it doesn't work. Otherwise, when I use a LAN connected machine's IP, it works.
Receiver:
MulticastSocket multiSocket = new MulticastSocket(3575);
InetAddress groupMulticast = InetAddress.getByName( "230.0.0.1" );
multiSocket.joinGroup(groupMulticast);
DatagramPacket packetReceive = new DatagramPacket( bufReceive, bufReceive.length );
try {
multiSocket.receive( packetReceive );
} catch (IOException e) { e.printStackTrace(); }
Sender:
MulticastSocket multiSocket = new MulticastSocket(3575);
InetAddress groupMulticast = InetAddress.getByName( "230.0.0.1" );
multiSocket.joinGroup(groupMulticast);
byte[] bufSend = new byte[255];
DatagramPacket packetSend = new DatagramPacket( bufSend, bufSend.length,
groupMulticast, 3575 );
try {
multiSocket.send(packetSend);
} catch (IOException e) { e.printStackTrace(); }
This sender doens't work. But if I change this:
InetAddress groupMulticast = InetAddress.getByName( "230.0.0.1" );
with this:
InetAddress groupMulticast = InetAddress.getByName( "192.168.0.21" );
where 192.168.0.21 is IP address of receiver connected in LAN, it works.
Ho can I send in multicasting?