I am a Java beginner, who is not familiar with Java socket programming. I need to handle the event of client side disconnection. I searched how to detect a socket disconnection with read*, write* function in Java, some one said:
read() will return -1
readLine() returns null
readXXX() for any other X throws EOFException.
The only really reliable way to detect a lost TCP connection is to write to it. Eventually this will throw an IOException: connection reset, but it takes at least two writes due to buffering.
I am not quite sure what does EOFException mean and what's difference between EOFException and IOException. The official manual said EOFException "Signals that an end of file or end of stream has been reachedunexpectedly during input. ", but I still don't understand what it is in TCP socket connection. Does it mean a tcp connection called close() function? What reason will cause IOException for a tcp connection? Thank you very much.