Java Socket setReceiveBufferSize() methodThe 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 1Test it NowOutput: Buffer size: 789 Example 2Test it NowOutput: Exception in thread "main" java.lang.IllegalArgumentException: invalid receive size at java.net.Socket.setReceiveBufferSize(Socket.java:1267) at com.javaTpoint.JavaSocketSetReceiveBufferSizeExample2.main( JavaSocketSetReceiveBufferSizeExample2.java:11) Example 3Test it NowOutput: Exception in thread "main" java.net.SocketException: Socket is closed at java.net.Socket.setReceiveBufferSize(Socket.java:1270) at com.javaTpoint.JavaSocketSetReceiveBufferSizeExample3.main( JavaSocketSetReceiveBufferSizeExample3.java:12) Next TopicJava Socket Class |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India