I have a serious problem here.
Lets say I have this code on the client:
socket.getSoTimeout(4*1000);
InputStream in = socket.getInputStream();
while(true)
{
int r = in.read();
if(r==-1) break;
System.out.print((char)r);
}
The socket receives data every second, so normally the timeout occurs when the connection is lost for whatever reason.
Sometimes, the TCP connection is lost (about once every 3-8 days - this is a very long lasting tcp-session!) and the server correctly notices the session is gone (IOException or a read of -1), however the client thinks it is still connected, and blocked indefinetly at read(), dispite the timeout of 4000ms! Stopping/restarting the ServerSocket at the server doesn’t help. The server sees all clients disconnect at the same time (which indicates a router reset/failure…?) and all clients are turned into zombies, blocking at read() forever, until I terminate the process of each client.
Any reason this can occur? Losing a TCP session isn’t bad, as long as I can notice this and reconnect… :-\