Datagram Sender : DatagramSocket « Network Protocol « Java

Datagram Sender


class DatagramSender {
  public static void main(String args[]) throws Exception {
    InetAddress ia = InetAddress.getByName(args[0]);
    // Obtain destination port
    int port = Integer.parseInt(args[1]);
    // Create a datagram socket
    DatagramSocket ds = new DatagramSocket();
    // Create a datagram packet
    byte buffer[] = args[2].getBytes();
    DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, port);


Related examples in the same category

1.Use DatagramSocket to send out and receive DatagramPacket
2.DatagramSocket sends out DatagramPacket
3.DatagramSocket receives DatagramPacket
4.Sending a Datagram
5.Receiving a Datagram
6.Joining a Multicast Group
7.Receiving from a Multicast Group
8.Sending to a Multicast Group
9.Receive DatagramPacket
10.Send a Datagram
11.User Datagram Protocol Programming
12.Read and write with DatagramPacket
13.Send back the response in a DatagramPacket