I am writing a proxy in Java. I want to know, how one may detect if the server or client has closed its socket? I am using pre-NIO sockets.
I have used read() method for reading. When I am reading (with read() ) as a client (from the server) if I get -1, does it mean that the server has closed
In the same way, If I am reading (with read()) from the client and get -1, does it mean that the client has closed the socket?
What is the best way to detect if a remote peer has closed the socket or not?
If I use methods like isInputShutdown() or isOutputShutdown(), will that help?
My main goal is read into a byte array until the remote peer has closed the socket? Any sample code will be much appreciated.