Java Socket setReuseAddress () methodThe setReuseAddress () method of Java Socket class enables or disables the SO_REUSEADDR socket option. The initial setting of SO_REUSEADDR is disabled. SyntaxParameterThe parameter 'on' states whether the SO_REUSEADDR option should be enabled or disabled. ReturnNA ThrowsSocketException - if the socket is closed or an error occurs while enabling or disabling the SO_REUSEADDR socket option. Example 1Test it NowOutput: SO_REUSEADDR option is enabled: true Example 2Test it NowOutput: SO_REUSEADDR option is disabled Example 3Test it NowOutput: Exception in thread "main" java.net.SocketException: Socket is closed at java.net.Socket.setReuseAddress(Socket.java:1448) at com.javaTpoint.JavaSocketSetReuseAddressExample3.main(JavaSocketSetReuseAddressExample3.java:15) 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