title: Severe UDP packet loss on some Android devices
body: <p>I have scoured the interwebz with no result. We are facing a problem where some Android devices experience severe packet loss. To give some background, the application connects to a specific Wifi and looks for UDP packets broadcast on port 17216. These packets are of size 832 bytes, excluding the wrapped headers, and are sent at a regular rate of four per second.</p>
  
  <p>We have only met the problem on two devices, a low-end Turbox Rubik II tablet and an ASUS Memo Pad HD 7. The other devices we've tested (phones and tablets) all gather the packets at the stipulated regular interval.</p>
  
  <p>The function that receives the packets is this:</p>
  
  <pre><code>public void run()
  {
      while (isUDPServerRunning)
      {
          try
          {
              socket.receive(packet);
  
              ProcessRawPacketData();
  
              DisplayLoggingInfo();
  
          }
          catch (IOException e)
          {
              Log.e("receive", e.getMessage());
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>And that is part of a <code>Runnable</code>. The socket is created thus:</p>
  
  <pre><code>byte[] buffer = new byte[1024];
  
  DatagramSocket socket;
  DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
  </code></pre>
  
  <p>with the socket being initialized in the <code>onCreate()</code> method of our <code>Service</code> extension:</p>
  
  <pre><code>socket = new DatagramSocket(SERVERPORT);
  </code></pre>
  
  <p>The packets are being received by the Wifi module. We've confirmed that by rooting one of the devices and installing a packet sniffer, so the problem must somehow be code related.</p>
  
  <p>On the affected devices packets are received correctly for a couple of seconds and then there is complete dropout that lasts for several seconds, so I estimate the loss to exceed 50%.</p>
  
  <p>Any help would be much appreciated. We are pulling our hair out.</p>
  
  <p><strong>Update</strong> I was mistaken about the packet sniffer. It seems that the packet sniffer is also losing several relevant packets on the rooted device. <em>Sometimes</em>, though, simply starting the packet sniffer fixes the issue! Turning Bluetooth on/off like suggested below does not seem to make a difference. Could this be another hardware issue?</p>
  
  <p><strong>Update 2</strong> Here is an example of the logs I'm printing immediately after the <code>socket.receive()</code> line. Notice how it skips half a minute's worth of packets and then works fine for a few seconds.</p>
  
  <pre><code>05-25 15:44:38.670: D/LOG(4393): Packet Received
  05-25 15:44:38.941: D/LOG(4393): Packet Received
  05-25 15:45:09.482: D/LOG(4393): Packet Received
  05-25 15:45:09.716: D/LOG(4393): Packet Received
  05-25 15:45:09.928: D/LOG(4393): Packet Received
  05-25 15:45:10.184: D/LOG(4393): Packet Received
  05-25 15:45:10.451: D/LOG(4393): Packet Received
  05-25 15:45:10.661: D/LOG(4393): Packet Received
  </code></pre>