关于winsock keepalive使用的几点疑问(基于TCP)
1、如果是服务端希望检测客户端的非正常掉线,KeepAlive属性是在服务端代码设置(连接建立成功之后)还是在客户端的代码设置呢?或者是两端都要设置?
2、关于结构体
struct tcp_keepalive {
u_long onoff;
u_long keepalivetime;
u_long keepaliveinterval;
};
不是非常明白keepalivetime和keepaliveinterval的含义,英文比较菜,MSDN的解释如下:
The keepalivetime member specifies the timeout, in milliseconds, with no activity until the first keep-alive packet is sent. The keepaliveinterval member specifies the interval, in milliseconds, between when successive keep-alive packets are sent if no acknowledgement is received.
可否认为是没经历keepaliveinterval时间,重新发送一次心跳包,一次成功的心跳包返回后,keepalivetime时间内不再发送心跳包?
3、对于完成端口而言,如果接收到成功的心跳包,GetQueuedCompletionStatus是否会返回呢?如果会返回的话,返回值为TRUE,lpNumberOfBytes 得到的值为0? 如果心跳包确认超时的话,GetQueuedCompletionStatus会得到返回值FALSE?
不知道说清楚了没,希望大家能够帮我解惑一下,不胜感激!