Search code examples
javasocketstelnetserversocket

Java sockets - Closing a telnet client connection to the server socket


I have created a server socket in Java, which accepts connections from a telnet client, and successfully communicates with the client, however when closing the client's socket on the server, the terminal on the client does not register the closing of the socket and does not show a "Connection to host lost" message, which is what I want.

The server socket must be able to handle multiple clients, so I cannot simply stop and restart it, otherwise all active clients will lose their connection to the server.

Maybe I am going about this wrong...? Any suggestions?

Thanks!


Solution

  • Ah, stupid mistake! I lost the reference to the client's socket and thus when trying to close it, an exception was thrown, but was suppressed... Simply closing the socket closes the client's telnet session.