new DatagramSocket()


import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class MainClass {

  public static void main(String args[]) {
    try {

      InetAddress ia = InetAddress.getByName("www.java2s.com");

      DatagramSocket ds = new DatagramSocket();

      byte buffer[] = "hello".getBytes();
      DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, 80);

      // Send the datagram packet
      ds.send(dp);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
Home 
  Java Book 
    Networking  

DatagramSocket:
  1. DatagramSocket
  2. new DatagramSocket()
  3. new DatagramSocket(int port)
  4. DatagramSocket: receive(DatagramPacket packet)
  5. DatagramSocket: send(DatagramPacket p)