title: Sending and receiving UDP packets?
body: <p>I have made a program to send an UDP packets from a client to a server.</p>
  
  <p>Here is the transmitter code:</p>
  
  <pre><code>import java.io.IOException;
  import java.net.*;
  
  public class JavaApplication9 {    
      public static void main(String[] args) throws UnknownHostException, SocketException, IOException  {
          // TODO code application logic here
          byte[] buffer = {10,23,12,31,43,32,24};
          byte [] IP = {-64,-88,1,106};
          InetAddress address = InetAddress.getByAddress(IP);
          DatagramPacket packet = new DatagramPacket(
                  buffer, buffer.length, address, 57
                  );
          DatagramSocket datagramSocket = new DatagramSocket();
          datagramSocket.send(packet);
          System.out.println(InetAddress.getLocalHost().getHostAddress());
      }
  }
  </code></pre>
  
  <p>The receiver code function is this:</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 (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>I have used the Wireshark program. The UDP packet is received in the Wireshark program at the receiver but the Java program wouldn't recognize it, the program just keeps listening to the port and nothing happens?</p>