Online Java Compiler By
JavaTpoint.com
import java.io.IOException; import java.net.*; public class JavaSocketGetKeepAliveExample3 { public static void main(String[] args) throws IOException { Socket socket = new Socket(); //closing the socket socket.close(); //getKeepAlive() returns a boolean indicating whether SO_KEEPALIVE option is enabled or not //it will return an exception, as the socket is already closed System.out.println("SO_KEEPALIVE is enabled: "+socket.getKeepAlive()); } }
Output