This content has been marked as final. Show 3 replies
when you create a socket and the other end close the connection (or the connection is lost for some technical problem) an IOException is throw.
you can close your application when this occurs.
I noticed that the exception is thrown immediately when the other side closes the connection. If your server can't close the connection explicitly (i.e. it crashes) you could wait for a while before the exception is thrown. to prevend it you could ping the server every x seconds.
when the server is off-line the IOException is thrown and you can close your application
You have 2 conditions that indicate that the socket has been closed. The usual one is that a read method returns a length of -1. This occurs if the other end closes properly. The other is an exception on either read or write, this occurs if the other end crashes or you close the socket and then try to use it.