Java Socket setReceiveBufferSize() methodLast Updated : 17 Mar 2025 The setReceiveBufferSize() method of Java Socket class sets the SO_RCVBUF option to the given value for the specified socket. The buffer size should be greater than zero else, it will throw an IllegalArgumentException. SyntaxParameterThe parameter 'size' represents the size to which the receive buffer size is to be set. ReturnNA ThrowsIllegalArgumentException - 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 1Output: Buffer size: 789 Example 2Output: Exception in thread "main" java.lang.IllegalArgumentException: invalid receive size at java.net.Socket.setReceiveBufferSize(Socket.java:1267) at com.tpointtech.JavaSocketSetReceiveBufferSizeExample2.main( JavaSocketSetReceiveBufferSizeExample2.java:11) Example 3Output: Exception in thread "main" java.net.SocketException: Socket is closed at java.net.Socket.setReceiveBufferSize(Socket.java:1270) at com.tpointtech.JavaSocketSetReceiveBufferSizeExample3.main( JavaSocketSetReceiveBufferSizeExample3.java:12) Next TopicJava Socket Class |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India