I want to differentiate the exceptions for server connection close on a client socket like if the server socket closes due to idle timeout that reason has to be generated on Client side as idle time out exception. Similarly for connection failure as connection failure exception and so on. Please help me to resolve this problem. Thanks in advance.
I want to differentiate the exceptions for server connection close on a client socket
Share
If the server closes the socket properly, there is only one possible exception at the client, not a series of different exceptions that the client has to catch and figure out. There is just an EOS indication: read() returns -1, readLine() returns null, readXXX() throws EOFException for any other X.
If the connection is dropped due to a network fault, it is possible for the client to get an IOException with the text ‘connection reset’. If the connection stays up but the server isn’t sending data and the client has a read timeout, the client will get a SocketTimeoutException. Neither of these implies that the server has closed the connection (although it is possible for the server to cause a connection reset, by means which I will not document here).
If you need to know why the server closed the socket, it will have to tell you via a message.