Javatpoint Logo
Javatpoint Logo

Java ServerSocket close() method

The close() method of ServerSocket class is used to close this socket. Any thread currently blocked in accept() will throw a SocketException. The associated channel is also closed by it if it has any.

Syntax

Specified by:

close in interface AutoCloseable

Specified by:

close in interface Closeable

Throws:

IOException - if an I/O error occurs when closing the socket.

Example 1

Server Application

Output:

Java ServerSocket close() method

Client Application:

Output:

Java ServerSocket close() method

Example 2:

Server Application

Output:

Java ServerSocket close() method

Client Application:

Output:

Java ServerSocket close() method
Next TopicJava ServerSocket





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA