FileDocCategorySizeDatePackage
getDatagramExample.javaAPI DocExample776Wed Apr 03 04:48:10 BST 2002None

getDatagramExample

public class getDatagramExample extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

  
    String s = "This is a test.";
  
    byte[] data = new byte[s.length()];
    s.getBytes(0, s.length(), data, 0);
    try {
      
      for(int i=0; ; ){
      InetAddress ia = InetAddress.getByName("68.3.10.51");
      int port = 25;
      DatagramPacket dp = new DatagramPacket(data, data.length, ia, port);
      System.out.println("This packet is addressed to " + dp.getAddress() + " on port " + dp.getPort());
      System.out.println("There are " + dp.getLength() + " bytes of data in the packet");
      System.out.println(new String(dp.getData(), 0, 0, dp.getLength()));
}
    }
    catch (UnknownHostException e) {
      System.err.println(e);
    }