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