title: Java UDP send/receive small example does not work
body: <p>I have written a small UDP client which is sending packets to a certain local address, and another small UDP client which will receive them and print on console its containt. They are not working currently, and I don't know why.</p>
  
  <p>This is the sending code:</p>
  
  <pre><code>import java.io.*;
  import java.net.*;
  
  class ClienteUDPtx {
  
    static final String HOST = "192.168.1.201";
    static final int PUERTO=20001;
  
    /**
      UDP Client which will send some UDP packets
      to local network address 192.168.1.201 on port 20001
    */
    public ClienteUDPtx( ) {
      try{
        int i = 0; 
  
        String[] ip_parts = HOST.split("."); 
        byte[] ip_num = {0, 0, 0, 0}; 
        for (String string : ip_parts) { 
           ip_num[i++] = Byte.valueOf(string); 
        } 
  
        InetAddress ip = InetAddress.getByAddress(ip_num); 
            DatagramSocket skCliente = new DatagramSocket(PUERTO, ip);
        DatagramPacket packet;
        File testFile = new File("test.txt");
        BufferedReader input =  new BufferedReader(new FileReader(testFile));
        String line;
  
        while((line=input.readLine())!=null) {
          System.out.println("Sending: " + line);
      byte message[] = line.getBytes();
      packet = new DatagramPacket(message, message.length, ip, PUERTO); 
          skCliente.send(packet);
      Thread.currentThread().sleep(1000);
        }
        line = "END";
        System.out.println("Sending: " + line);
        byte message[] = line.getBytes();
        packet = new DatagramPacket(message, message.length, ip, PUERTO); 
        skCliente.send(packet);
  
        input.close();
        skCliente.close();
      } catch( Exception e ) {
        System.out.println( e.getMessage() );
      }
    }
  
  
    public static void main( String[] arg ) {
      new ClienteUDPtx();
    }
  
  }
  </code></pre>
  
  <p>This is the receiving code:</p>
  
  <pre><code>import java.io.*;
  import java.net.*;
  
  class ClienteUDPrx {
  
    static final String HOST = "192.168.1.101";
    static final int PUERTO=20001;
  
    /**
      UDP Client which will listen for incoming UDP packets
      from local network address 192.168.1.101 on port 20001
      and will print its content on console
    */
  
    public ClienteUDPrx( ) {
      try{
        int i = 0; 
  
        String[] ip_parts = HOST.split("."); 
        byte[] ip_num = {0, 0, 0, 0}; 
        for (String string : ip_parts) { 
           ip_num[i++] = Byte.valueOf(string); 
        } 
  
        InetAddress ip = InetAddress.getByAddress(ip_num); 
        DatagramSocket skCliente = new DatagramSocket(PUERTO, ip);
        byte[] buffer = new byte[2048];
        DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
  
  
        while(true){
          // Wait to receive a datagram
          skCliente.receive(packet);
          String lineaLeida = new String(buffer, 0, packet.getLength());
          System.out.println(packet.getAddress().getHostName() + ": "+ lineaLeida);
          if(lineaLeida.equals("END")) break; 
        }
        skCliente.close();
        System.out.println( "Transmission ended" );
      } catch( Exception e ) {
        System.out.println( e.getMessage() );
      }
    }
  
  
    public static void main( String[] arg ) {
      new ClienteUDPrx();
    }
  
  }
  </code></pre>
  
  <p>Any idea?</p>