Online Java Compiler By
JavaTpoint.com
import java.io.IOException; import java.net.*; public class JavaSocketSetSoTimeoutExample2 { public static void main(String[] args) throws IOException { //calling the constructor of the socket class Socket socket = new Socket(); //integer timeout value //the timeout value can be zero int timeout=0; //setSoTimeout() method enables or disables the SO_TIMEOUT option with the given timeout value, in milliseconds. socket.setSoTimeout(timeout); //getSoTimeout() method returns the setting for SO_TIMEOUT option System.out.println("Timeout value: "+socket.getSoTimeout()); } }
Output