This content has been marked as final. Show 5 replies
Intervening firewalls can time out your connection. You're on the right track but when you get this exception, or indeed any exception, during I/O on a socket there is no alternative but to close it and in your case re-establish the connection with a new socket.
Thanks for your reply.
Well I guess it can be a firewall issue. Although sock.isConnected returns true, something must be happening on the TCP level. I must figure that out because I need to have a persistent connection. Using Ethereal I found that my client is writing the first byte only, after what the server replies with TCP RST (reset)... I don't understand, isn't TCP supposed to keep the connection alive by itself (hmm maybe firewall working here?.. don't know..)? Will I have to keep sending pings to the server or something?
Socket.isConnected just tells you whether you have personally called Socket.connect() or new Socket(host, port,...). It doesn't tell you anything about the state of the connection.
You should certainly issue periodic application 'pings' at suitable intervals, and many application protocols do this. For example, Java RMI reuses connections that are less than 15 seconds old but only if they pass a ping test.
In general however you can't insist on a persistent connection over TCP/IP, especially if you have this kind of hardware in the circuit. What you can do is recognize when the connection has been lost and form a new one. The network is going to fail somewhere some time and your program has to be robust against that.
Is any body have knowledge of persistent connection need the details about it.
This thread is about a persistent error. Start your own.