Java DatagramPacket and DatagramSocket not receiving data
<p>I am trying to receive a simple string using <code>DatagramPacket</code> and <code>DatagramSocket</code> class in Java.</p>

<p>Here is my code:</p>

<pre><code>public static void main(String [] args){

    DatagramSocket aSocket = null;

    try{
        aSocket= new DatagramSocket();
        String aMessage = "my message";
        System.out.println("1");
        byte [] m = aMessage.getBytes();
        InetAddress aHost = InetAddress.getByName("localhost");
        int serverPort = 6789;
        DatagramPacket request = new DatagramPacket(m,aMessage.length(),aHost,serverPort);
        System.out.println("2");
        aSocket.send(request);
        System.out.println("3");
        byte [] buffer = new byte[1000];
        System.out.println("4");
        DatagramPacket reply = new DatagramPacket(buffer,buffer.length);
        aSocket.receive(reply);
        System.out.println("5");
        System.out.println("DATA RECEIVED" + reply.getData());
        aSocket.close();

    }
    catch(SocketException ex){
       ex.printStackTrace();
    }

    catch(IOException ioe){
       ioe.printStackTrace();
    }
}
</code></pre>

<p>It's not printing the received data. I have put <code>System.out.println</code> just to see where the code is executed, and it stops at 4, it does not print 5, meaning the problem is just below 4. Why am I not receiving the data, can anybody help me with this please?</p>
