Online Java Compiler By
JavaTpoint.com
import java.io.IOException; import java.net.*; public class JavaSocketSetSoLingerExample4 { public static void main(String[] args) throws IOException { //calling the constructor of the socket class Socket socket = new Socket(); //closing the socket socket.close(); //disabling the SO_LINGER option boolean on=true; //setting the integer value for timeout //the timeout value should be greater or equal to 0 int timeout=10; //setSoLinger() method enables or disables the SO_LINGER option with the given linger time in seconds. //it will throw an error, as the socket is already closed socket.setSoLinger(on,timeout); //getSoLinger() method returns the setting if the SO_Linger option is set System.out.println("Send Buffer size: "+socket.getSoLinger()); } }
Output