title: Strange behaviour with Datagram in UDP receive function in Android
body: <p>I'm trying to implement an UDP test to learn about it. I've a server application in c# for windows and a client app for Android.</p>
  
  <p>I'm trying to implement a homemade discovery service. Server is continuosly listening for UDP packages with a fixed string ("LazyRemote"). When it receives that string it sends another string to the client ("LazyRemote_192.168.1.17:2016")
  I've checked with wireshark that the data sent in both directions is correct but I'm receiving something incorrect in the client application. </p>
  
  <p>The code for android is this:</p>
  
  <pre><code>buttonConnect.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View arg0) {
  
              progress.show();
              //This code is executed when user clicks connect button. As it could be a long running operation, it's executed in a new thread to avoid blocking UI
              Thread thread = new Thread(new Runnable() {
                  @Override
                  public void run() {
  
                      String ipAddress = "";
                      SocketClass my_socketClass = new SocketClass();
                      InetAddress UDPaddress = my_socketClass.getBroadcastAddress();
                      int UDPport = 15000;
  
                      if(initializationDone == false){
                          initializationDone = true;
  
                          try {
                              socket_send = new DatagramSocket();
                              socket_send.setBroadcast(true);
                              socket_send.setSoTimeout(6000);
                              socket_receive = new DatagramSocket(UDPport, InetAddress.getByName("0.0.0.0"));
                          } catch (Exception e) {
                              e.printStackTrace();
                          }
                      }
  
                      try {
  
                          byte[] send_buff = "LazyRemote".getBytes();
                          DatagramPacket sendPacket = new DatagramPacket(send_buff, send_buff.length,UDPaddress,UDPport);
                          socket_send.send(sendPacket);
  
                      }catch (Exception ex){
  
                          showToast("Imposible enviar primer ack");
                      }
  
  
                      byte[] receive_buff = new byte[30];
                      DatagramPacket receivePacket = new DatagramPacket(receive_buff, receive_buff.length);
  
                      try {
  
                          socket_receive.receive(receivePacket);
                          String receivedData = new String(receivePacket.getData(), "UTF-8");
                          if (receivedData.contains("LazyRemote")) {
  
  
                              SocketClass my_socket = new SocketClass(receivePacket.getAddress().toString().substring(1), 2016);
                              SocketClass.ConnectionStatus connectionStatus = my_socket.establishConnection();
  
                              //Remove progressdialog after establishConnection finishes.
                              progress.dismiss();
  
                              //Check connection status.
                              if (connectionStatus.status == true) {
  
                                  Thread.sleep(1000);
                                  socket_receive.close();
                                  socket_send.close();
                                  Intent intent = new Intent(MainActivity.this, ActionPerformer.class);
                                  startActivity(intent);
                                  finish();
                              }
                          }
                      } catch (Exception ex) {
                          progress.dismiss();
                          showToast("No se han encontrado servidores");
                      }
                      //mLock.release();
                  }
              });
              thread.start();
          }
      });
  </code></pre>
  
  <p>The problem is that receive function is working but it is receiving wrong data. (It is receiving the same string that the client sends to the server to initialize descovery ("LazyRemote")).</p>
  
  <p>It must be a stupid mistake but i can't solve it. Thanks a lot.</p>