Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid device not receiving multicast package
    primarykey
    data
    text
    <p>I am developing a chat application where Android clients will exchange their IP's using multicasting(UDP).</p> <p>Every device will send its ip to multiple clients(all the devices running this app) in one separate Thread. There will be another receiver thread which will listen to these multicast packets. Here is my code.</p> <p>//Multicasting code.</p> <pre><code>DatagramSocket socket = new DatagramSocket(9898); byte buff[] = ip.getBytes(); DatagramPacket packet = new DatagramPacket(buff, buff.length, InetAddress.getByName("224.0.0.1"),9999); socket.send(packet); socket.close(); </code></pre> <p>//Receiver code</p> <pre><code>MulticastSocket socket = new MulticastSocket(9999); InetAddress group = InetAddress.getByName("224.0.0.1"); socket.joinGroup(group); DatagramPacket packet; byte[] buf = new byte[256]; byte b = 'x'; //just a separator for time being Arrays.fill(buf,b); packet = new DatagramPacket(buf, buf.length); String received= ""; while(received!=null) { socket.receive(packet); received = new String(packet.getData()); received = received.substring(0,received.indexOf('x')); this.setIp(received); System.out.println("Address: " + received); } socket.leaveGroup(group); socket.close(); </code></pre> <p>The problem is every device prints its own address. It seems it never listens to other multicast packages(I mean it should print other ip's as well). I also get a below log, not sure if that's related.</p> <pre><code>11-04 23:56:17.985: I/OSNetworkSystem(603): mcastAddDropMembership interfaceIndex=0 </code></pre> <p>Any help will be appreciated. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload