title: Android UDP Socket IOException: sendto failed: EPERM (Operation not permitted)
body: <p>I wrote an application in Android that communicates with a UDP socket periodically.
  I create a datagramSocket and I periodically send and receive a packet from the server every 5 seconds, this is a part of the code:</p>
  
  <pre><code>Thread commTh = new Thread(new Runnable() {
  
      @Override
      public void run() {
          try {
              ds = new DatagramSocket();
              serverAddr = InetAddress.getByName(ip);
              ds.connect(serverAddr, port);
  
              while(exitThread) {
  
                  ....
  
                  DatagramPacket dp;
                  dp = new DatagramPacket(data.getBytes(),
                          data.length(), serverAddr, port);
  
                  ds.setSoTimeout(DEFAULT_TIMEOUT);
  
                  ds.send(dp);
  
                  byte[] lMsg = new byte[SOCKET_BYTE];
                  dp = new DatagramPacket(lMsg, lMsg.length);
                  ds.receive(dp);
  
                  ....
  
                  Thread.sleep(5000);
  
  
              }
          }
          catch (Exception e) {
              e.printStackTrace();
  
          }
      }
  });
  </code></pre>
  
  <p>Randomly after a few tens of minutes I get this exception:</p>
  
  <pre><code>W/System.err: java.io.IOException: sendto failed: EPERM (Operation not permitted)
  W/System.err:     at         libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:576)
      at libcore.io.IoBridge.sendto(IoBridge.java:544)
      at java.net.PlainDatagramSocketImpl.send(PlainDatagramSocketImpl.java:125)
      at java.net.DatagramSocket.send(DatagramSocket.java:721)
  </code></pre>
  
  <p>why I get an operation not permitted? I have internet permissions in my manifest</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  </code></pre>