title: Java UDP Receiver not receiving data
body: <p>Here is my Sender program</p>
  
  <pre><code>import java.net.*;
  
  class Send{
      public static void main(String[] args) {
          try{
              //setup
              DatagramSocket socket=new DatagramSocket();
              byte[] buffer=new byte[100];
              InetAddress address=InetAddress.getLocalHost();
              System.out.println("Address:"+address);
              DatagramPacket packet=new DatagramPacket(buffer,buffer.length,address,10000);
  
              //get data
              String data="Hello";
  
              //send data
              buffer=data.getBytes();
              System.out.println("Sending data");
              socket.send(packet);
          }
          catch(Exception ex)
          {
              ex.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>Here is the Receiver Program</p>
  
  <pre><code>import java.net.*;
  
  class Listen{
      public static void main(String[] args) {
          try{
              //set up
              DatagramSocket socket=new DatagramSocket(10000);
              byte[] buffer=new byte[100];
              DatagramPacket packet=new DatagramPacket(buffer,buffer.length);
              //recieve
              System.out.println("Started Listening");
              socket.receive(packet);
              //print
              String receivedData=new String(packet.getData());
              System.out.println(receivedData);               
              System.out.println("Done!");
          }
          catch(Exception ex)
          {
              ex.printStackTrace();
          }
  
      }
  }
  </code></pre>
  
  <p>What I get is, when the Listener is running, it seems to be waiting for the sender to send data(prints "started Listening"). When sender is executed, it seems to run properly as well(prints "Sending data"). receiver executes further as well(prints "Done!"), but the packet remains empty.</p>
  
  <p>What might be the problem?</p>