title: Can't receive UDP packet on android?
body: <p>I tried to implement UDP server on Android, i can send packets to server, but can't received it. Also i tried run receiver without android, it works. Where is the problem?</p>
  
  <p>Local sender for Testing:</p>
  
  <pre><code>int send_packet(uint8_t* data) {
      int retcode;
      int socket_out;
      int broadcast = 1;
      struct sockaddr_in addr;
  
      socket_out = socket(AF_INET, SOCK_DGRAM, 0);
      if ( socket_out &lt; 0 )
          return -1;
  
      setsockopt(socket_out, SOL_SOCKET, SO_BROADCAST, &amp;broadcast, sizeof broadcast);
  
      memset(&amp;addr, 0, sizeof(addr));
      addr.sin_family = AF_INET;
      addr.sin_addr.s_addr = htonl(INADDR_BROADCAST);
      addr.sin_port=htons(PORT_NUMBER);
  
      retcode = sendto(socket_out, data, sizeof(packet_data_t), 0,
          (struct sockaddr *) &amp;addr, sizeof(addr));
      perror("sendto");
  
      close(socket_out);
  
      return 0;
  }
  </code></pre>
  
  <p>Android receiver:</p>
  
  <pre><code>public void run(){
     try {
         byte[] buffer = new byte[BUFFER_SIZE];
         DatagramSocket socket = new DatagramSocket(getPort());
         //socket.setBroadcast(true);
         while(true){
             DatagramPacket packet = new DatagramPacket(buffer, buffer.length );
             socket.receive(packet);
             (new CallbackWrapper(getPacketReciever())).run();
         }
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>ps I am running my application on a HTC Legend, not on emulator</p>