Sending a Datagram - Java Network

Java examples for Network:UDP

Description

Sending a Datagram

Demo Code

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 send(InetAddress dst, int port, byte[] outbuf, int len) {
    try {//from  w w w.ja  v a2 s  .  c  o  m
      DatagramPacket request = new DatagramPacket(outbuf, len, dst, port);
      DatagramSocket socket = new DatagramSocket();
      socket.send(request);
    } catch (SocketException e) {
    } catch (IOException e) {
    }
  }
}

Related Tutorials