Javatpoint Logo
Javatpoint Logo

Java ServerSocket setReceiveBufferSize() method

The setReceiveBufferSize() method of Java ServerSocket class sets a default proposed value for the SO_RCVBUF option for sockets accepted from this ServerSocket. The Buffer size must be greater than 0.

Syntax

Parameter

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

Return

NA

Throws

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

IllegalArgumentException- if the value is 0 or negative.

Example 1

Output:

Buffer size: 89

Example 2

Output:

Exception in thread "main" java.lang.IllegalArgumentException: negative receive size
	at java.net.ServerSocket.setReceiveBufferSize(ServerSocket.java:845)
	at com.javaTpoint.JavaServerSocketSetReceiveBufferSizeExample2.main(JavaServerSocketSetReceiveBufferSizeExample2.java:11)

Example 3

Output:

Exception in thread "main" java.lang.IllegalArgumentException: negative receive size
	at java.net.ServerSocket.setReceiveBufferSize(ServerSocket.java:845)
	at com.javaTpoint.JavaServerSocketSetReceiveBufferSizeExample3.main(JavaServerSocketSetReceiveBufferSizeExample3.java:14)
Next TopicJava ServerSocket





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA