|Subject:||Re: Problem when connection dies|
|Posted by:||Remy Lebeau (TeamB) (firstname.lastname@example.org)|
|Date:||Wed, 25 May 2005|
"Filipe" <fili…@silicon.inf.br> wrote in message
> But in some cases, when the connection to the server dies ( i.e
> a firewall restart or anything ) my application don't get notfied
> that it is disconnected and just keeps trying to read/write data
> to that socket.
That is very likely. Sockets do not handle abnormal disconnects very well.
When it happens, 99% of the time the lower levels of the socket architecture
have no way of knowing that it happened at all.
> I've already tested with CheckForDisconnect(true,true) to break
> the flow when this happens, but without success.
That only works when the underlying socket architecture knows that the
socket is invalid. Otherwise, it cannot report any errors until the socket
times out internally, which can take a long time.
Your best option is to just use your own timeouts. If you don't receive
data for a period of time that you are expecting data to arrive, then just
assume the socket is lost and restart it as needed. If the server does not
send data for a long time, then if the protocol supports it, send data to
the server periodically and see if it responds in a timely fashion.
However, if the protocol does not dictate that the server should send back
some kind of acknowledgement when you send data to it, and if there is no
kind of noop/ping/keepalive feature implemented in the protocol, then you
are going to have problems detecting abnormal disconnections.
Problem when connection dies posted by Filipe on Wed, 25 May 2005