new DatagramPacket(byte[] buf, int length, InetAddress address, int port) : DatagramPacket « java.net « Java by API






new DatagramPacket(byte[] buf, int length, InetAddress address, int port)


/*
 * Output:
 *  
 */

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();
    }
  }
}
           
       








Related examples in the same category

1.new DatagramPacket(byte[] buffer, int bufferLength)
2.DatagramPacket: getAddress()
3.DatagramPacket: getData()
4.DatagramPacket: getPort()
5.DatagramPacket: getSocketAddress()