DatagramSocket sends out DatagramPacket : DatagramSocket « Network Protocol « Java






DatagramSocket sends out DatagramPacket

 

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

public class Main {
  public static void main(String[] args) throws Exception {
    DatagramSocket ds = new DatagramSocket();
    String str = "hello world";
    InetAddress ia = InetAddress.getByName("127.0.0.1");
    DatagramPacket dp = new DatagramPacket(str.getBytes(), str.length(), ia, 3000);
    ds.send(dp);
    ds.close();
  }
}

   
  








Related examples in the same category

1.Use DatagramSocket to send out and receive DatagramPacket
2.DatagramSocket receives DatagramPacket
3.Datagram Sender
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