Java Socket.setKeepAlive(boolean on)
Syntax
Socket.setKeepAlive(boolean on) has the following syntax.
public void setKeepAlive(boolean on) throws SocketException
Example
In the following code shows how to use Socket.setKeepAlive(boolean on) method.
/*w w w. j av a2 s. c o m*/
import java.net.Socket;
public class Main {
public static void main(String[] args) throws Exception {
Socket client = new Socket("google.com", 80);
client.setKeepAlive(true);
System.out.println(client.getKeepAlive());
client.close();
}
}