我正在为Windows编写套接字程序并尝试在客户端和服务器之间创建通信。我正在使用select()api。但它是错误的错误:从不成功中恢复任何人都可以帮助我吗?
while(1)
{
//memset(buffer, 0, sizeof(buffer));
//blocks only for specified time
status = select(0, &ReadSet, NULL, NULL, &tv);
if (status == -1)
{
extern int errno;
cerr << "ERROR: Select unsuccessful: Error" << WSAGetLastError() << endl;
cout << "ERRNO: " << _errno << endl;
}
else if (status == 0)
{
cout<<"Timeout occurred! No data after 500ms" << endl;
}
else
{
if (FD_ISSET(clientSocket, &ReadSet))
{
// Receieve74.
numrcv = recv(clientSocket, buffer, MAXBUFLEN, NO_FLAGS_SET);
if (numrcv == SOCKET_ERROR)
{
cerr << "ERROR: recvfrom unsuccessful" << endl;
}
// Print out receieved socket data92.
cout << "Message rcvd from client" << buffer<< endl;
}
}