Online Java Compiler By
JavaTpoint.com
import java.io.IOException; import java.net.*; public class JavaSocketGetTcpNoDelayExample3 { public static void main(String[] args) throws IOException { //calling the constructor of the socket class Socket socket = new Socket(); //closing the socket socket.close(); //enabling the SO_TIMEOUT option boolean on=true; //setTcpNoDelay() method enables or disables the SO_TIMEOUT option socket.setTcpNoDelay(on); //getTcpNoDelay() returns the setting for SO_TIMEOUT option //it will return an error, as the socket is already closed System.out.println("SO_TIMEOUT option is enabled: "+socket.getTcpNoDelay()); } }
Output