views:

30

answers:

2

Hi,

I'm trying to find out how exactly keep-alive works in .NET but link from here doesn't work. Could anybody post a link with specification?

What I'm looking for:

  • I would like to know how often are the keep-alive packets sent.

  • Do I have to set KeepAlive via command:

    s.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);

    only at the server side or even the client has to set this flag?

Thanks!

+3  A: 

Not sure this is what you are looking for, but the SocketOptionName enum has a KeepAlive member, as can be seen here.

From the documentation, you would use it this way:

s.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
Oded
Thanks. I would like to know how often are the keep-alive packets sent. And this is what would like to see in the documentation.
MartyIX
@MartyIX - The default according to RFC 1122 is 2 hours, and this is how windows is setup. See this blog post - it is a global registry setting. http://www.pcreview.co.uk/forums/thread-2666745.php
Oded
@Oded: I found it on MSDN too (http://msdn.microsoft.com/en-us/library/ee470551(VS.85).aspx). Thank you!
MartyIX
+1  A: 

I have a writeup on my blog about keepalives. Short answer: both sides need a keepalive of some kind, but if you have a "poll" initiated from one side, then that can act as a keepalive. Also, I recommend building the keepalive right into the protocol rather than using the socket setting.

On my blog entry I don't go into a great deal of detail about the keepalive socket setting, because I believe it's not very useful (see the blog post for details).

Note that the "global registry setting" was changed with Windows 2000. It now can be changed on a per-connection basis. I still don't recommend it as a keepalive, though (see my blog post for details).

Stephen Cleary
Thanks for the link. Interesting and useful!
MartyIX