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 www.jav a  2s.c om
      DatagramPacket request = new DatagramPacket(outbuf, len, dst, port);
      DatagramSocket socket = new DatagramSocket();
      socket.send(request);
    } catch (SocketException e) {
    } catch (IOException e) {
    }
  }
}

Related Tutorials