Java Socket setSendBufferSize () method

The setSendBufferSize () method of Java Socket class sets the SO_SNDBUF option to the given value for this socket. The size value should be greater than 0.

Syntax

Parameter

The parameter 'size' represents the size to which the send buffer size is set.

Return

NA

Throws

IllegalArgumentException - if the size is 0 or less than zero.

SocketException - if an error is there in the underlying protocol, such as a TCP error.

Example 1

Test it Now

Output:

Send Buffer size: 67

Example 2

Test it Now

Output:

Exception in thread "main" java.lang.IllegalArgumentException: negative send size
	at java.net.Socket.setSendBufferSize(Socket.java:1193)
	at com.javaTpoint.JavaSocketSetSendBufferSizeExample2.main(
	JavaSocketSetSendBufferSizeExample2.java:11)

Example 3

Test it Now

Output:

Exception in thread "main" java.net.SocketException: Socket is closed
	at java.net.Socket.setSendBufferSize(Socket.java:1196)
	at com.javaTpoint.JavaSocketSetSendBufferSizeExample2.main(
	JavaSocketSetSendBufferSizeExample2.java:13)




Latest Courses