java - MulticastSocket receives message twice -


i send messages wifi access point via multicastsocket , replies twice. if try send message me self, message twice again. receiver code:

protected void doinbackground(void... params) {                  string ltext;                 byte[] lmsg = new byte[globalconfig.max_udp_datagram_len];                 datagrampacket dp = new datagrampacket(lmsg, lmsg.length);                 multicastsocket ds = null;                 try {                     ds = new multicastsocket (32001);                     inetaddress serveraddr = inetaddress.getbyname("224.237.124.120");                     ds.joingroup(serveraddr);                     while (serveractive) {                          ds.receive(dp);                         log.d("udp packet received", dp.tostring());                         ltext = new string(lmsg, 0, dp.getlength());                         receivedmessage = ltext;                         dosomething();                      }                 } catch (socketexception e) {                     e.printstacktrace();                 } catch (ioexception e) {                     e.printstacktrace();                 } {                     if (ds != null) {                         ds.close();                     }                 }                 return null;             } 

i tried send via datagramsocket , via multicastsocket - no matter. messages alway twice. don't understand why!

edit: logcat:

i/gatewaycontroller﹕ message sent ...  d/udp packet received﹕ java.net.datagrampacket@422dc860 d/udp packet received﹕ java.net.datagrampacket@422dc860 

edit2: sender code

protected void doinbackground(void... params) {                  datagramsocket ds = null;                 try {                     ds = new datagramsocket();                     inetaddress serveraddr = inetaddress.getbyname("224.237.124.120");                     datagrampacket dp;                     dp = new datagrampacket(bytemsg, bytemsg.length,                             serveraddr, 32000);                     ds.send(dp); 

i tried send via datagramsocket , via multicastsocket - no matter. messages alway twice. don't understand why!

edit: logcat:

i/gatewaycontroller﹕ message sent ... 
d/udp packet received﹕ java.net.datagrampacket@422dc860 d/udp packet received﹕ java.net.datagrampacket@422dc860 

this not evidence received same message twice. evidence receive same byte array. try logging message content.

however multicast udp, , udp not guarantee delivery, or single delivery, or sequenced delivery, remains possible duplicates. if that's semantically important, need detect via sequence numbers.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -