Send a Datagram : DatagramSocket « Network Protocol « Java






Send a Datagram

 

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) {
    }

  }
}

   
  








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.Datagram Sender
5.Sending a Datagram
6.Receiving a Datagram
7.Joining a Multicast Group
8.Receiving from a Multicast Group
9.Sending to a Multicast Group
10.Receive DatagramPacket
11.User Datagram Protocol Programming
12.Read and write with DatagramPacket
13.Send back the response in a DatagramPacket