Online Java Compiler By
JavaTpoint.com
import java.io.IOException; import java.net.*; public class JavaSocketSetSoLingerExample2 { public static void main(String[] args) throws IOException { //calling the constructor of the socket class Socket socket = new Socket(); //disabling the SO_LINGER option boolean on=false; //setting the integer value for timeout int timeout=90; //setSoLinger() method enables or disables the SO_LINGER option with the given linger time in seconds. //if the SO_LINGER option is disabled, it returns -1 socket.setSoLinger(on,timeout); //getSoLinger() method returns the setting if the SO_Linger option is set System.out.println("Timeout value: "+socket.getSoLinger()); } }
Output