title: Java - sending message from one PC to another via UDP connection
body: <p>When I tested with both client and server on localhost its works. But then I split the client and server to different machines with different IP addresses and now the packets are not being received on the client side. Can anyone spot the problem with my code:</p>
  
  <p>Client:</p>
  
  <pre><code>class Csimudp {
      public static DatagramSocket ds;
      public static byte buffer[] = new byte[1024];
  
      public static void Myclient() throws Exception {
          while (true) {
              DatagramPacket p = new DatagramPacket(buffer, buffer.length);
              ds.receive(p);
              System.out.println(new String(p.getData(), 0, p.getLength()));
          }
      }
  
      public static void main(String args[]) throws Exception {
          System.out.println("for quitting client press ctrl+c");
          ds = new DatagramSocket(777);
          Myclient();
      }
  }
  </code></pre>
  
  <p>Server:</p>
  
  <pre><code>class Ssimudp {
      public static DatagramSocket ds;
      public static byte buffer[] = new byte[1024];
  
      public static void MyServer() throws Exception {
          int pos = 0;
          while (true) {
              int c = System.in.read();
              switch (c) {
              case '~':
                  System.out.println("\n Quits");
                  return;
              case '\r':
                  break;
              case '\n':
                  ds.send(new DatagramPacket(buffer, pos, InetAddress
                          .getByName("117.201.5.150"), 777));
                  pos = 0;
                  break;
              default:
                  buffer[pos++] = (byte) c;
              }
          }
      }
  
      public static void main(String args[]) throws Exception {
          System.out.println("server ready....\n please type here");
          ds = new DatagramSocket(888);
          MyServer();
      }
  }
  </code></pre>