Java DatagramSocket .setSendBufferSize (int size)
Syntax
DatagramSocket.setSendBufferSize(int size) has the following syntax.
public void setSendBufferSize(int size) throws SocketException
Example
In the following code shows how to use DatagramSocket.setSendBufferSize(int size) method.
/*from ww w. j a v a2 s . co m*/
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
public class Main {
public static void main(String args[]) {
try {
InetAddress ia = InetAddress.getByName("www.java2s.com");
DatagramSocket ds = new DatagramSocket();
byte buffer[] = "hello".getBytes();
DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, 80);
ds.setSendBufferSize(1000);
ds.send(dp);
} catch (Exception e) {
e.printStackTrace();
}
}
}