In article <41bf66ac$0$65124$(E-Mail Removed)>, Frank de Bot wrote:
> Hi,
>
> I've written 2 apps in C, a client and a server. But I can't seem to
> handle the sudden disconnect of one of the two. According the Socket FAQ
> I could get a ECONNRESET from a read if the peer has gone away. How can
> I check if the "other side" has gone away or not? (I've already
> programmed something with pings, but it doesn't please me)
>
> Thanks in advanced,
>
> Frank de Bot
>
Hi Frank,
If your application disconnects when no data is actively being sent,
then one side of your app sends data to the other side after the
disconnect, your read call will block until the app gets a reply from
the other side. TCP will retransmit the data up to 12 times over 9
minutes if I recall correctly. After the 9 minutes expires you'll get
ETIMEDOUT.
You'll get ECONNRESET if you lose the connection and then it comes back
up again (physical link broken or server rebooted).
Again, if I recall correctly, The only way to get around the 9 minute
waiting time without setting SO_KEEPALIVE is to use a heartbeat function
where you send data back and forth between clients and if the data is
not received within a specific time frame, assume that the host is down.
Regards,
Jason
|