Set socket to blocking mode

(1) The socket works in non-blocking mode, and set the acceptance timeout
C / C ++ code
?
1
2
3
4
5
6
7
8
9
// 创建套接字
SOCKET sock = WSASocket(AF_INET, SOCK_STREAM, IPPOROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED);
if (INVALID_SOCKET == sock)
{
  printf ( "WSASocket call failed. Error code: %d" , WSAGetLastError());
}
//
int  nTimeout = 5*1000; //设置超时5秒
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, ( char *)&nTimeout,  sizeof (nTimeout));

Guess you like

Origin blog.csdn.net/qq_38204688/article/details/78583575