MSDN中TCP keepalive时效的说明以及设置TCP Keepalive的代码
来源:互联网 发布:mac鼠标在windows系统 编辑:程序博客网 时间:2024/04/28 05:49
说明:
A TCP keep-alive packet is simply an ACK with the sequence number set to one less than the current sequence number for the connection. A host receiving one of these ACKs will respond with an ACK for the current sequence number.
翻译:
一个TCP keep-alive 包是一个简单的ACK,该ACK包内容为 一个比当前连接sequence number 小于一的包。主机接受到这些ACKs会返回一个包含当前sequence number 的ACK包。
说明:
Keep-alives can be used to verify that the computer at the remote end of a connection is still available.
翻译:
Keep-alives一般被用来验证远端连接是否有效。
说明:
TCP keep-alives can be sent once every KeepAliveTime (defaults to 7,200,000 milliseconds or 2 hours), if no other data or higher-level keep-alives have been carried over the TCP connection.
翻译:
如果该连接上没有其他数据被传输,或者更高level 的 keep-alives被传送,keep-alives 在每个KeepAliveTime被发送。(默认是 7,200,000 milliseconds ,也就是2个小时)。
说明:
If there is no response to a keep-alive, it is repeated once every KeepAliveInterval seconds. KeepAliveInterval defaults to 1 second. NetBT connections, such as those used by many parts of the Microsoft networking functionality, send NetBIOS keep-alives more frequently, so usually no TCP keep-alives will be sent on a NetBIOS connection.
原翻译:
如果对于keep-alive连接端没有回应,他继续将在每KeepAliveInterval秒发送,KeepAliveInterval默认为1秒,在NETBT连接,比如Microsoft networking的很多功能性的部分,发送NETBios keep-alives频率高,所以,在一个NetBios连接中,TCP keep-alives不被发送。
此处感谢 网友of123 修正翻译(给大家造成的误解博主向所有的读者表示歉意):
如果没有收到 keep-alive 应答,keep-alive 将在每 KeepAliveInterval 秒重发一次。KeepAliveInterval 默认为1秒。如 Microsoft 网络功能中很多部分中采用的 NETBT 连接,更常见的是发送 NETBios keep-alives,所以,在 NetBios 连接中通常不发送TCP keep-alives。
说明:
TCP keep-alives are disabled by default, but Windows Sockets applications can use the SetSockOpt function to enable them.
翻译:
TCP保持连接默认被禁用,但是微软Sockets应用程序可以使用SetSockOpt函数去启用他们。
几点比较重要的说明:
1:TCP 的默认时效是2个小时。
2:如果发送Keep-alive没有回应,将会在KeepAliveInterval再次发送,不过这里是否需要系统来进行判断,并断开连接?
设置keepalive代码如下:
判断掉线并处理:
A TCP keep-alive packet is simply an ACK with the sequence number set to one less than the current sequence number for the connection. A host receiving one of these ACKs will respond with an ACK for the current sequence number.
翻译:
一个TCP keep-alive 包是一个简单的ACK,该ACK包内容为 一个比当前连接sequence number 小于一的包。主机接受到这些ACKs会返回一个包含当前sequence number 的ACK包。
说明:
Keep-alives can be used to verify that the computer at the remote end of a connection is still available.
翻译:
Keep-alives一般被用来验证远端连接是否有效。
说明:
TCP keep-alives can be sent once every KeepAliveTime (defaults to 7,200,000 milliseconds or 2 hours), if no other data or higher-level keep-alives have been carried over the TCP connection.
翻译:
如果该连接上没有其他数据被传输,或者更高level 的 keep-alives被传送,keep-alives 在每个KeepAliveTime被发送。(默认是 7,200,000 milliseconds ,也就是2个小时)。
说明:
If there is no response to a keep-alive, it is repeated once every KeepAliveInterval seconds. KeepAliveInterval defaults to 1 second. NetBT connections, such as those used by many parts of the Microsoft networking functionality, send NetBIOS keep-alives more frequently, so usually no TCP keep-alives will be sent on a NetBIOS connection.
原翻译:
如果对于keep-alive连接端没有回应,他继续将在每KeepAliveInterval秒发送,KeepAliveInterval默认为1秒,在NETBT连接,比如Microsoft networking的很多功能性的部分,发送NETBios keep-alives频率高,所以,在一个NetBios连接中,TCP keep-alives不被发送。
此处感谢 网友of123 修正翻译(给大家造成的误解博主向所有的读者表示歉意):
引用
如果没有收到 keep-alive 应答,keep-alive 将在每 KeepAliveInterval 秒重发一次。KeepAliveInterval 默认为1秒。如 Microsoft 网络功能中很多部分中采用的 NETBT 连接,更常见的是发送 NETBios keep-alives,所以,在 NetBios 连接中通常不发送TCP keep-alives。
说明:
TCP keep-alives are disabled by default, but Windows Sockets applications can use the SetSockOpt function to enable them.
翻译:
TCP保持连接默认被禁用,但是微软Sockets应用程序可以使用SetSockOpt函数去启用他们。
几点比较重要的说明:
1:TCP 的默认时效是2个小时。
2:如果发送Keep-alive没有回应,将会在KeepAliveInterval再次发送,不过这里是否需要系统来进行判断,并断开连接?
设置keepalive代码如下:
- tcp_keepalive live,liveout;
- live.keepaliveinterval=500;
- live.keepalivetime=3000; //勘误 1分钟是 60000 以此类推
- live.onoff=TRUE;
- int iRet = setsockopt(Socket,SOL_SOCKET,SO_KEEPALIVE,(char *)Opt,sizeof(int));
- if(iRet == 0){
- DWORD dw;
- if(WSAIoctl(Socket,SIO_KEEPALIVE_VALS,&live,sizeof(live),&liveout,sizeof(liveout),&dw,NULL,NULL)== SOCKET_ERROR){
- //Delete Client
- return;
- }
- }
判断掉线并处理:
- BOOL bReturn = GetQueuedCompletionStatus(
- g_hIOCompletionPort,
- &dwBytesTransfered,
- (LPDWORD)&lpContext,
- &pOverlapped,
- INFINITE);
- if (bReturn== false){
- //Client has gone delete client and close socket
- }
- MSDN中TCP keepalive时效的说明以及设置TCP Keepalive的代码
- VC中如何设置Socket的TCP/IP KeepAlive机制(MSDN)
- TCP的KeepAlive
- TCP、http的keepalive
- TCP和http的keepalive
- TCP keepalive
- tcp keepalive
- TCP keepAlive
- TCP keepalive
- TCP keepalive
- tcp Keepalive
- TCP KeepAlive
- Tcp KeepAlive
- TCP Keepalive
- tcp keepalive
- 设置TCP的keepalive来进行网络联调
- HTTP的KeepAlive与TCP的LINGER
- Nginx的keepalive_timeout和TCP的keepalive
- .NET正则基础之——.NET正则匹配模式
- JAVA MAIL JavaMail详解
- Java6学习笔记62——显示IP
- 主生产计划
- 在word中如何输入分数
- MSDN中TCP keepalive时效的说明以及设置TCP Keepalive的代码
- 使用Silverlight Toolkit实现弹窗---ChildWindow
- [数据库:未解决] 求比上年同期时去年为闰年,遇到的问题!?
- IE无法查看源文件原因及解决办法
- 最小生成树----Prim算法
- Java6学习笔记63——TCP客户端/服务器端
- SAP学习日志01---DW与BI
- Java6学习笔记64——UDP客户端/服务器端
- 【Folye】算法实验题12.1 自动应答器