title: Send and receive data on UDP Socket java android
body: <p>I am able to properly send my data through UDP socket , but when I receive data it keeps on waiting at receive command I don't know what is causing this.
  Please have a look at my code below.</p>
  
  <p>I am able to properly receive data at server side from android device, but when I send data from server side to android device it doesn't receive. but when I send data from server to any other client e.g PC application it receive and displays data properly.</p>
  
  <pre><code>class Task implements Runnable {
      @Override
      public void run() {
          try {
              String messageStr = "feed";
              int server_port = 8888;
              InetAddress local = InetAddress.getByName("10.0.2.2");
              int msg_length = messageStr.length();
              byte[] message = messageStr.getBytes();
  
  
              DatagramSocket s = new DatagramSocket();
             // 
  
              DatagramPacket p = new DatagramPacket(message, msg_length, local, server_port);
              s.send(p);//properly able to send data. i receive data to server
  
              for (int i = 0; i &lt;= 20; i++) {
                  final int value = i;
                  message = new byte[30000];
                  p = new DatagramPacket(message,message.length );
                  s.receive(p); //keeps on waiting here but i am sending data back from server, but it never receives
                  final byte[] data =  p.getData();;
                  try {
  
  
  
                      Thread.sleep(1000);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
                  handler.post(new Runnable() {
                      @Override
                      public void run() {
                          progressBar.setProgress(value);
                          imageView.setImageBitmap(BitmapFactory.decodeByteArray(data,0,data.length));
                      }
                  });
              }
          }
          catch(Exception ex)
          {
  
          }
      }
  }
  </code></pre>