Java Socket setSoTimeout() methodThe setSoTimeout () method of Java Socket class enables or disables the SO_TIMEOUT option with the given timeout value, in milliseconds. The timeout value should be greater than 0 otherwise, it will throw an error. SyntaxParameterThe parameter 'timeout' represents a specific timeout in milliseconds. ReturnNA ThrowsSocketException - if an error is there in the underlying protocol, such as a TCP error. Example 1Test it Now Test it NowOutput: Timeout value: 90987789 Example 2Test it NowOutput: Timeout value: 0 Example 3Test it NowOutput: Exception in thread "main" java.lang.IllegalArgumentException: timeout can't be negative at java.net.Socket.setSoTimeout(Socket.java:1139) at com.javaTpoint.JavaSocketSetSoTimeoutExample3.main(JavaSocketSetSoTimeoutExample3.java:13) Example 4Test it NowOutput: Exception in thread "main" java.net.SocketException: Socket is closed at java.net.Socket.setSoTimeout(Socket.java:1137) at com.javaTpoint.JavaSocketSetSoTimeoutExample4.main(JavaSocketSetSoTimeoutExample3.java:16) 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