如何在 C++ 中通过 Winsock 检查客户端是否断开连接?
最佳答案
Beej's Network Programming Guide
如果你在阻塞模式下调用recv并且它返回0字节读取,套接字已经断开,否则它等待接收字节。
看看这个FAQ 2.12
this 上的选择示例页面。
int nRet;
if(( nRet = select( 0, &fdread, NULL, NULL, NULL )) == SOCKET_ERROR )
{
// Error condition
// Check WSAGetLastError
}
if( nRet > 0 )
{
// select() will return value 1 because i m using only one socket
// At this point, it should be checked whether the
// socket is part of a set.
if( FD_ISSET( s, &fdread ))
{
// A read event has occurred on socket s
}
}
关于c++ - 如何检查客户端是否通过 C++ 中的 Winsock 断开连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/685951/