void CListenSocket::OnAccept(int nErrorCode) { // TODO: Add your specialized code here and/or call the base class CServerSocket* pSvr = new CServerSocket; CSocket::Accept(*pSvr); pSvr->m_pMainWnd = m_pMainWnd; CString strPear; UINT nPort; pSvr->GetPeerName(strPear, nPort); m_lstSvrSocket.AddTail(pSvr); OutputDebugString("-------------------------------------------------\r\n"); OutputDebugString("*************************************************\r\n"); /* // Keep Alive SOCKET sock = pSvr->m_hSocket; tcp_keepalive inKeepAlive = {0}; // 输入参数 unsigned long ulInLen = sizeof(tcp_keepalive); tcp_keepalive outKeepAlive = {0}; // 输出参数 unsigned long ulOutLen = sizeof(tcp_keepalive); unsigned long ulBytesReturn = 0; // 设置socket的keep alive为5秒,并且发送次数为3次 inKeepAlive.onoff = 1; inKeepAlive.keepaliveinterval = 1000; // 两次KeepAlive探测间的时间间隔 inKeepAlive.keepalivetime = 5000; // 开始首次KeepAlive探测前的TCP空闭时间 if (WSAIoctl(sock, SIO_KEEPALIVE_VALS, (LPVOID)&inKeepAlive, ulInLen, (LPVOID)&outKeepAlive, ulOutLen, &ulBytesReturn, NULL, NULL) == SOCKET_ERROR) { return; // return 0; } */ CSocket::OnAccept(nErrorCode); }