0

I am trying to connect to a multicast group and send udp packets from a server to a client.

i wrote the right permissions on the manifest

the server code:

private DatagramSocket datagramSocket;
datagramSocket = new DatagramSocket();
InetAddress IPAddress;
IPAddress = InetAddress.getByName("230.0.0.1");
DatagramPacket sendPacket;
sendPacket = new DatagramPacket(data, data.length, IPAddress, port);
datagramSocket.send(sendPacket);

the client code:

private MulticastSocket soketmulNHC;
soketmulNHC = new MulticastSocket(8900);
soketmulNHC = new MulticastSocket(8900);
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
MulticastLock multicastLock = wifi.createMulticastLock("multicastLock");
multicastLock.acquire();
byte[] buffer = new byte[Data.MAX_PACKET_SIZE];             
InetAddress group = InetAddress.getByName("230.0.0.1");                     
soketmulNHC.joinGroup(group);
DatagramPacket receivePacket = new DatagramPacket(buffer,buffer.length,group,8900);                             
soketmulNHC.receive(receivePacket);

and i got this exception:

Exception in recieving
java.net.SocketException: No such device
at org.apache.harmony.luni.platform.OSNetworkSystem.setSocketOption(Native Method)
at org.apache.harmony.luni.net.PlainDatagramSocketImpl.setOption(PlainDatagramSocketImpl.java:198)
at org.apache.harmony.luni.net.PlainDatagramSocketImpl.join(PlainDatagramSocketImpl.java:137)
at java.net.MulticastSocket.joinGroup(MulticastSocket.java:190)

i also tried to add the interface part from this link Multicast - no such device and then i got:

SocketException in sending: java.net.SocketException: Network is unreachable

maybe there is a problem using S2 galaxy for multicasting? i need your help, thanks.

Community
  • 1
  • 1
Lior Yaron
  • 1
  • 1
  • 2

1 Answers1

0

For most devices (if they have more than one network device), you need to explicitly select which network device should be used for joining the multicast group.

Sebastian Dröge
  • 2,063
  • 11
  • 9