我正在尝试在连接时自动向客户端发出服务器请求,但我不断收到 10057 的 WSAGetLastError。我已经设置了从客户端到服务器的请求而没有问题,所以我不明白为什么我不能做相反的事情?也许服务器必须等待客户端的第一次“发送”,但我不明白为什么会这样?
我正在使用:
-asynchronous socket -TCP
-s
是一个有效的套接字
-i'v 循环 RequestInfo 几次,但没有任何变化-select
() 返回 0
-datasize 返回 -1,错误码为 10057
谢谢你 !!!
服务器:
//first - following the debugger
FD_ACCEPT
int acc = accept(s, (struct sockaddr*)&fromm, &fromlenn); //success
if(acc <= 0)
{
eLOGG << "\nFAIL FD_ACCEPT: " << WSAGetLastError();
}
RequestInfo();
//then
RequestInfo()
{
stringstream ssConverter;
ssConverter.clear(); ssConverter.str(string());
ssConverter << "00aa"; //request signal
bool blogin = false;
eLOG << "signal is: *" << ssConverter.str() << "*";
int bufSize = ssConverter.str().length();
fd_set writefds;
struct timeval timeout;
timeout.tv_sec = 3;
timeout.tv_usec = 0;
FD_ZERO(&writefds);
FD_SET(s, &writefds);
int sel = select(s, NULL, &writefds, NULL, &timeout);
if(sel == SOCKET_ERROR)
{
eLOG << "\nselect - read fail: " << WSAGetLastError();
}
if(sel == 0)
{
eLOG << "\nselect - not connected: " << WSAGetLastError();
}
if (FD_ISSET(s, &writefds))
{
eLOG << "\n FD_ISSET";
}
eLOG << "\nauth socket is: " << s;
int dataSize = send(s, ssConverter.str().c_str(), bufSize, 0);
if(dataSize < bufSize)
{
eLOG << "\n FD_ISSET";
}
//...etc
}