我的服务器挂起test=accept(ServSock[i],(LPSOCKADDR)&From,&FromLen);
,直到收到连接。
如果10秒后没有连接,服务器是否关闭?如何实现呢?
SOCKET test;
test=accept(ServSock[i],(LPSOCKADDR)&From,&FromLen);
AmountRead=recv(test, Buffer,sizeof(Buffer),0);
string xx="abbbbbbfffff55555 rrrrcggggb";
const char *fin=new char;
fin=xx.c_str();
char m;
fin=xx.c_str();
RetVal=send(test, fin,xx.length(), 0);
cout<<"sent: "<<fin<<"\n";
closesocket(test);
答案 0 :(得分:0)
fd_set read;
FD_ZERO(&read);
FD_SET(ServSock[i], &read);
struct timeval timeout = { .tv_sec = 10, .tv_usec = 0 };
if (select(ServSock[i] + 1, &read, NULL, NULL, &timeout) == -1)
return 1;
if (FD_ISSET(ServSock[i], &read)) {
int ret = accept(ServSock[i],(LPSOCKADDR)&From,&FromLen);
}
else {
return 1;
}