Java Socket getReceiveBufferSize() method

The getReceiveBufferSize() method of Java Socket class returns the buffer size (SO_RCVBUF option) for this socket.

Syntax

Parameter

NA

Returns

The getReceiveBufferSize() method returns the buffer size or the SO_RCVBUF option for this socket.

Throws

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

Example 1

Test it Now

Output:

Buffer size: 789

Example 2

Test it Now

Output:

Buffer size: 65536

Example 3

Test it Now

Output:

Exception in thread "main" java.lang.IllegalArgumentException: invalid receive size
	at java.net.Socket.setReceiveBufferSize(Socket.java:1267)
	at com.javaTpoint.JavaSocketGetReceiveBufferSizeExample3.main(JavaSocketGetReceiveBufferSizeExample3.java:11)

Example 4

Test it Now

Output:

Exception in thread "main" java.net.SocketException: Socket is closed
	at java.net.Socket.setReceiveBufferSize(Socket.java:1270)
	at com.javaTpoint.JavaSocketGetReceiveBufferSizeExample4.main(JavaSocketGetReceiveBufferSizeExample4.java:12)




Latest Courses