Online Java Compiler By
JavaTpoint.com
import java.io.IOException; import java.net.*; public class JavaSocketSetSoLingerExample1 { public static void main(String[] args) throws IOException { //calling the constructor of the socket class Socket socket = new Socket(); //enabling the SO_LINGER option boolean on=true; //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. socket.setSoLinger(on,timeout); //getSoLinger() method returns the setting if the SO_Linger option is set System.out.println("Timeout value: "+socket.getSoLinger()); } }
Output