Re: Should a socket client detect loss of network connection



The following is what RFC 1122 has to say on the subject:

4.2.3.6 TCP Keep-Alives

Implementors MAY include "keep-alives" in their TCP
implementations, although this practice is not universally
accepted. If keep-alives are included, the application MUST
be able to turn them on or off for each TCP connection, and
they MUST default to off.

Keep-alive packets MUST only be sent when no data or
acknowledgement packets have been received for the
connection within an interval. This interval MUST be
configurable and MUST default to no less than two hours.

It is extremely important to remember that ACK segments that
contain no data are not reliably transmitted by TCP.
Consequently, if a keep-alive mechanism is implemented it
MUST NOT interpret failure to respond to any specific probe
as a dead connection.

An implementation SHOULD send a keep-alive segment with no
data; however, it MAY be configurable to send a keep-alive
segment containing one garbage octet, for compatibility with
erroneous TCP implementations.

Microsoft's implementation certainly conforms.

TCP keep-alives are certainly not good enough for maintaining
bindings at NAT routers.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@xxxxxxxx
MVP VC FAQ: http://vcfaq.mvps.org
=====================================

"Roger Hunen" <rhunen@xxxxxxxxx> wrote in message
news:461bd016$0$323$e4fe514c@xxxxxxxxxxxxxxxxx
"Alexander Nickolov" <agnickolov@xxxxxxxx> wrotel...
That "apart from" statement answers your question. It's the only
way.

setsockopt (...., SO_KEEPALIVE, ....) looks like that other way to me.

The only problem with SO_KEEPALIVE is that the Windows default
keepalive timeout is very long (2 hours) and that you cannot set this
timeout at the socket level (it is a system wide registry setting).

Regards,
-Roger
--
E-mail: rhunen@xxxxxxxxx
Home: http://www.xs4all.nl/~rhunen
ADSL: http://adsl.hunen.net

"Angus" <nospam@xxxxxxxxx> wrote in message
news:ewX3O44eHHA.4136@xxxxxxxxxxxxxxxxxxxxxxx
Thank you, I have checked with the client and it is a router causing
this
problem. So what you suggest sounds like the easiest solution.

It would be most convenient if the client could 'detect' that the
connection
'session' was no longer valid. Is there any way of checking this apart
from
sending data to the server? I assume not.

Angus




"Alexander Nickolov" <agnickolov@xxxxxxxx> wrote in message
news:uXVPrbseHHA.5052@xxxxxxxxxxxxxxxxxxxxxxx
Sounds like a NAT router in between dropping its TCP binidings
for your connection due to inactivity. You must include some sort
of keep-alive mechanism in your protocol in case of regular data
inactivity, otherwise you are subject to the NAT router issue.
BTW, before you ask there's no standard threshold when a NAT
router considers a TCP connection inactive. Personally I wouldn't
trust a conection with 5 minutes inactivity alive through a NAT router.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@xxxxxxxx
MVP VC FAQ: http://vcfaq.mvps.org
=====================================

"Angus" <nospam@xxxxxxxxx> wrote in message
news:uicy3KseHHA.5056@xxxxxxxxxxxxxxxxxxxxxxx
Hello

I have written a socket client and a server. When I test on my test
system
it seems to work fine. But a user has reported that if they leave
the
system running with no activity for over an hour then the server
stops
sending data to the client.

I have setup on a test system on different computers and I don't see
this
problem after one hour. Most of the activity is server to client.

So in my testing I tried taking the ethernet cable out of the server
PC.
Neither my server or client seemed to detect this. Should they be
able
to?
If so how?

Has anyone seen this type of problem? Any ideas on how to
troubleshoot
it
and resolve? It is only a problem apparently after a long period of
inactivity. If there is data sent from server to client within a
reasonable
period there is no problem. I think if the user goes to lunch (or
away
for
a period) then the way the system works there would be no data from
the
server. If they get back after an hour or so then they need to
re-connect
from client to see any further data communication.

Angus













.



Relevant Pages

  • Re: NAT and keepaliveopen connection over TCP
    ... Implementors MAY include "keep-alives" in their TCP ... There's no minimum set time how long a NAT router should ... time-out inactive connections at the server. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Notification when network connection loss...
    ... For sends the tcp stack will retry sending the data 5 times by default. ... This value controls how often TCP attempts to verify that an idle connection ... Keep-alive packets are not sent by default. ... TCP keep-alives can be sent once every ...
    (microsoft.public.windowsce.app.development)
  • RE: Intermittent Error When Calling Web Service from ASP.NET
    ... Have you tried making keep-alives not used from the proxy that the front ... >exceptions thrown while trying to invoke a Web service from ASP.NET. ... >server that in turn invokes a Web service on a middle-tier server. ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: IIS HTTP 1.1 keep-alive potential issue
    ... I need to ask you to better define what "HTTP 1.1 keep-alives ... with Connection: Keep-Alive header or HTTP 1.1 without Connection: Close ... Server *must* allow keep-alive. ...
    (microsoft.public.inetserver.iis)
  • Re: sysctl_tcp_keepalive_time
    ... Implementors MAY include "keep-alives" in their TCP ... Keep-alive packets MUST only be sent when no data or ...
    (Linux-Kernel)