Java Socket setKeepAlive() methodThe setKeepAlive() method of Java Socket class returns a Boolean value 'true' if the write-half of the socket connection has been closed successfully else it returns false. SyntaxParameterThe parameter 'on' represents whether the socket should be enabled or not. ReturnNA ThrowsSocketException - if an error is there in the underlying protocol, such as a TCP error. Example 1Test it NowOutput: SO_KEEPALIVE is enabled: true Example 2Test it NowOutput: SO_KEEPALIVE is not enabled... Example 3Test it NowOutput: Exception in thread "main" java.net.SocketException: Socket is closed at java.net.Socket.setKeepAlive(Socket.java:1309) at com.javaTpoint.JavaSocketSetKeepAliveExample3.main(JavaSocketSetKeepAliveExample3.java:13) Next TopicJava Socket Class |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India