Socket socket = new Socket(ipAddress, port); socket.setKeepAlive(true);
Socket socket = new Socket(ipAddress, port); socket.setKeepAlive(false);In this example, we again create a new socket object but this time we set its keepAlive property to false. This means that the TCP connection will not send any periodic keep-alive messages to the server. The java.net package is part of the core Java API.