TCP Keep-Alive Messages

TCP Keep-Alive Messages

(2010-05-19 09:31:23)
标签:

it

分类:socket

From:MSDN

A Transmission Control Protocol (TCP) keep-alive packet is an acknowledgment (ACK) with the sequence number set to one less than the current sequence number for the connection. The Transmission Control Protocol/Internet Protocol (TCP/IP) stack can automatically generate these keep-alive messages to verify that the computer at the remote end of a connection is still available.

For example, a client application that downloads data from a server and then performs a long series of calculations might need to periodically verify that the server that will receive its results is still reachable. If the server is not reachable, and there is no alternative server to upload the results to, it might not be useful for the application to continue its calculations. Similarly, a server holding resources in a cache might need to periodically verify that its clients are still connected, so that it can deallocate cached resources used by disconnected clients.

Implementing Keep-Alive Messages 来源:(http://blog.sina.com.cn/s/blog_415a66f00100ikjr.html) - TCP Keep-Alive Messages_joewan_新浪博客

When implementing an existing protocol, developers must follow the protocol's guidelines on use or nonuse of keep-alives. When designing a new protocol, developers specify their own keep-alive strategies. Some reasons that a developer might decide not to use TCP keep-alives include:

  • The application protocol includes its own higher-level keep-alive mechanism.

  • The application does not need to do anything, such as invalidate cache entries, if a connection has been idle for a long while.

  • The application runs on a busy network and TCP keep-alives would generate too much traffic.

A host receiving a keep-alive ACK responds with an ACK for the current TCP sequence number.

Configuring Keep-Alive Messages on Windows

Two per-interface registry settings under the key 

/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Tcpip/Parameters

control the behavior of TCP/IP keep-alives:

  • The KeepAliveTime value specifies how long the TCP connection sits idle, with no traffic, before TCP sends a keep-alive packet. The default is 7,200,000 milliseconds (ms) or 2 hours.

  • The KeepAliveInterval value indicates how many milliseconds to wait for a response after sending a keep-alive before repeating the keep-alive. If no response is received, the TCP/IP stack continues sending keep-alives at this interval until a response is received or until the stack reaches the packet retry limit specified in the TCPMaxDataRetransmissions registry key.KeepAliveInterval defaults to 1 second (1000 ms).

NetBIOS over TCP (NetBT) connections, such as those used by many Microsoft networking components, send NetBIOS keep-alives more frequently than the usual rate for TCP keep-alives. Thus, generally no TCP keep-alives are sent on a NetBIOS connection.

TCP keep-alives are disabled by default, but Windows Sockets applications can use the setsockoptfunction to enable them on a per-connection basis.

Note  If the developer elects to use TCP keep-alive messages on a particular connection, the timing of those messages is specified by the registry values described preceding. It is not possible to use different timing on different keep-alive requests.

来源:(http://blog.sina.com.cn/s/blog_415a66f00100ikjr.html) - TCP Keep-Alive Messages_joewan_新浪博客
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值