tcp keeplive

keepalive参数设置代码如下:
// 开启KeepAlive
BOOL bKeepAlive = TRUE;
int nRet = ::setsockopt(socket_handle, SOL_SOCKET, SO_KEEPALIVE, 
(char*)&bKeepAlive, sizeof(bKeepAlive));
if (nRet == SOCKET_ERROR)
{
return FALSE;
}


// 设置KeepAlive参数
tcp_keepalive alive_in                = {0};
tcp_keepalive alive_out                = {0};
alive_in.keepalivetime                = 5000;                // 
开始首次KeepAlive探测前的TCP空闭时间
alive_in.keepaliveinterval        = 1000;                // 两次KeepAlive探测间的时间间隔
alive_in.onoff                                = TRUE;
unsigned long ulBytesReturn = 0;
nRet = WSAIoctl(socket_handle, SIO_KEEPALIVE_VALS, &alive_in, sizeof(alive_in),
&alive_out, sizeof(alive_out), &ulBytesReturn, NULL, NULL);
if (nRet == SOCKET_ERROR)
{
return FALSE;
}

你可能感兴趣的:(tcp keeplive)