Send a Datagram : UDP Client « Network « Java Tutorial






import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class Main {
  public static void main(String[] argv) throws Exception {
  }

  public static void senddatagram(InetAddress target, int port, byte[] outbuf, int len) {

    try {
      DatagramPacket request = new DatagramPacket(outbuf, len, target, port);

      DatagramSocket socket = new DatagramSocket();
      socket.send(request);
    } catch (SocketException e) {
    } catch (IOException e) {
    }

  }
}








19.17.UDP Client
19.17.1.UDP Echo Client
19.17.2.UDP Discard Client
19.17.3.UDP Time Client
19.17.4.Send a Datagram
19.17.5.Sending a Datagram
19.17.6.Receiving a Datagram
19.17.7.Read and write with DatagramPacket
19.17.8.User Datagram Protocol Programming