Online Java Compiler By
JavaTpoint.com
import java.io.IOException; import java.net.*; public class JavaSocketSetSoTimeoutExample4 { public static void main(String[] args) throws IOException { //calling the constructor of the socket class Socket socket = new Socket(); //closing the socket socket.close(); //integer timeout value //the timeout value should be greater than 0, else it will throw an exception int timeout=980; //setSoTimeout() method enables or disables the SO_TIMEOUT option with the given timeout value, in milliseconds. //it will throw an error, as the socket is already closed socket.setSoTimeout(timeout); //getSoTimeout() method returns the setting for SO_TIMEOUT option System.out.println("Timeout value: "+socket.getSoTimeout()); } }
Output