Why is my android receiver dropping 10-60% of UDP broadcast packets? -
i have 802.3 wired transmitter application on computer i've written broadcast udp packets every 10ms. each broadcast packet contains 4-byte integer value unique particular packet, allows me figure out on receiver end how many packets have been dropped.
i have verified transmitter works wireshark. set 4 802.11 receivers (2 android phones , 2 laptop computers) on same network. laptops received 95% of udp broadcast packets; 1 phone received 89%; other phone received 40%.
why?
here part of android receiver code:
public class netthread extends thread { int[] pkt_nums; int p; netthread(int[] pkt_nums) { this.pkt_nums = pkt_nums; (int i=0; i<pkt_nums.length; i++) { pkt_nums[i]=0; } p = 0; } @override public void run() { receivedata(); } public void receivedata() { // request permission network operations in manifest file...done // start network side of things datagramsocket sock = null; datagrampacket pkt = null; try { byte[] data = new byte[c.payload_max]; sock = new datagramsocket(c.net_port); sock.setsotimeout(c.net_so_timeout); pkt = new datagrampacket(data, 0, c.payload_max); while (true) { thread.sleep(0); // allow interrupt try { sock.receive(pkt); int length = pkt.getlength(); boolean success = writetobuffer(pkt.getdata(), length); if (!success) break; } catch (interruptedioexception e) { // thrown when timeout occurs log.d(c.dtag, "net: no packets yet"); } } log.d(c.dtag, "buffer full. done receiving."); if (sock != null) sock.close(); } catch (interruptedexception x) { log.d(c.dtag, "net: interrupted."); } catch (socketexception e) { log.d(c.dtag, "net: socketexception"); e.printstacktrace(); } catch (ioexception e) { log.d(c.dtag, "net: ioexception"); e.printstacktrace(); } if (sock != null) sock.close(); } public boolean writetobuffer(byte[] data, int length) { // each packet should have 4 bytes - number int pkt_num = data[0] & 0x000000ff | data[1]<<8 & 0x0000ff00 | data[2]<<16 & 0x00ff0000 | data[3]<<24 & 0xff000000; if (p < pkt_nums.length) { pkt_nums[p++] = pkt_num; return true; // success } else { return false; } } }
i declare above class in main activity follows:
mnetthrd = new netthread(pkt_nums); mnetthrd.setdaemon(true); mnetthrd.start();
i try boosting thread priority now, have feeling i'm doing wrong. need @ least 95% of udp broadcast packets application.
more details: laptops , phones situated next each other, 30 ft router line-of sight visibility. laptop 1 received 95% of packets. laptop 2 received 94%. phone 1 received 89%. phone 2 received 40%. both ran same app. other network traffic minimal. dropped packets in android typically happen in groups of 20-50 @ time. 802.11 has clean channel. each packet contains 4-byte payload.
is there drastically wrong receiver code or issue altogether?
Comments
Post a Comment