Java Socket close() methodThe close() method of Java Socket class closes the specified socket. Once the socket has been closed, it is not available for further networking use. If the socket has a channel, the channel is also closed. SyntaxParameterNA ReturnNA Specified by
ThrowsIOException - if an I/O error occurs when closing this socket. Example 1Test it NowOutput: Inet address: localhost/127.0.0.1 Port number: 1085 After calling the close() method... Inet address: localhost/127.0.0.1 Port number: 1085 Example 2Test it NowOutput: Exception in thread "main" java.net.SocketException: Socket is closed at java.net.Socket.bind(Socket.java:625) at com.javaTpoint.JavaSocketCloseExample2.main(JavaSocketCloseExample2.java:17) 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