I have a Client Socket Connected to Server. My Server is some Different Application (Not a Java Application). If the Server is Closed, I want my Client Application to be Closed.Can some help me out in doing so... Thank U Very much.
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.