Online Java Compiler By
JavaTpoint.com
import java.io.IOException; import java.net.*; public class JavaSocketSetReceiveBufferSizeExample3 { public static void main(String[] args) throws IOException { //calling the constructor of the socket class Socket socket = new Socket(); //closing the socket socket.close(); //setting the buffer size with the help of setReceiveBufferSize() method //it will throw an exception, as the socket is already closed socket.setReceiveBufferSize(10); //getReceiveBufferSize() method returns the buffer size for this socket System.out.println("Buffer size: "+socket.getReceiveBufferSize()); } }
Output