我在winsock2上有一个简单的HTTP服务器。
我将我的浏览器的“获取”请求发送到服务器,并获取内容的响应。之后,浏览器关闭连接并发送新请求。我该怎么做才能接受新连接?
我尝试
connectEvent = WSACreateEvent();
WSAEventSelect( sHttp, connectEvent, FD_READ);
WSANETWORKEVENTS netevent;
WSAEventSelect(sHttp,connectEvent, FD_ACCEPT);
WSAWaitForMultipleEvents(1, &connectEvent, FALSE, WSA_INFINITE, FALSE);
WSAEnumNetworkEvents(sHttp,connectEvent,&netevent);
if (netevent.lNetworkEvents & FD_CLOSE){
printf("closed\n");
closesocket(sHttp);
}
if (netevent.lNetworkEvents & FD_ACCEPT){
printf("accepted\n");
struct sockaddr_in client = {};
int clientSize = sizeof(client);
sHttp = accept(sHttp, (struct sockaddr*)&client, &clientSize);
WSAEventSelect(sHttp,connectEvent, FD_READ | FD_WRITE | FD_CLOSE);
}
但不接受连接