UDP client sending data to server, but not receiving response
<p>I am creating a simple Android app which can communicate with my PC. On my computer I have a very simple UDP server in Java. </p>

<pre><code>public void run(){

    try{
        DatagramSocket serverSocket = new DatagramSocket(port);
        byte[] receiveData = new byte[8];
        byte[] sendData = new byte[8];

        while(true)
           {
              DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
              serverSocket.receive(receivePacket);
              String sentence = new String( receivePacket.getData());
              System.out.println("RECEIVED: " + sentence);
              InetAddress IPAddress = receivePacket.getAddress();
              String sendString = "polo";
              sendData = sendString.getBytes();
              DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port);
              serverSocket.send(sendPacket);
           }
    }catch (Exception e){
    }
}
</code></pre>

<p>and I have another simple piece of code inside my android app which sends a UDP packet to the server and awaits the response.</p>

<pre><code>public void checkServerOnline(View v) {
    try {
        int port = 46001;
        DatagramSocket clientSocket = new DatagramSocket();
        clientSocket.setSoTimeout(1800);
        InetAddress IPAddress = InetAddress.getByName(host);
        byte[] sendData = new byte[8];
        byte[] receiveData = new byte[8];
        String sentence = "marco";
        sendData = sentence.getBytes();
        DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port);
        clientSocket.send(sendPacket);
        DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
        clientSocket.receive(receivePacket);
        clientSocket.close();
    } catch (Exception e) {
    }
</code></pre>

<p>The problem I am having is that my Client is timing out waiting for a response. The server is definitely receiving the string "marco" and is presumably sending the response "polo", but the client is not receiving it. I've tried removing the timeout on the client, but it just freezes up until I force close the application.</p>

<p>Can anyone see an error in my code? I can't understand why it won't work. I've managed to successfully setup a TCP Server and client with the same setup, but cannot seem to do UDP.</p>
