我正在尝试使我的套接字“基于事件”。以下是我尝试过的:
VOID createServerSocket()
{
WSADATA wsa;
//Initialise winsock//
if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)
{
//"WinSock Initialization FAILED",
}
//Create a socket//
SOCKET newSocketIdentifier;
SOCKADDR_IN newSocket;
if((newSocketIdentifier = socket(AF_INET , SOCK_DGRAM , 0 )) == INVALID_SOCKET)
{
//Socket Creation Failed
}
//Socket Created//
//Prepare the sockaddr_in structure//
newSocket.sin_family = AF_INET;
newSocket.sin_addr.s_addr = INADDR_ANY;
newSocket.sin_port = htons(8888);
//Bind//
if( bind(newSocketIdentifier ,(struct sockaddr *)&newSocket, sizeof(SOCKADDR_IN)) == SOCKET_ERROR)
{
//Bind Failed
}
//Bind Done//
WSAEVENT NewEvent = WSACreateEvent();
WSAEventSelect(newSocketIdentifier, NewEvent, FD_READ | FD_WRITE); //made the socket "newSocketIdentifier" event based for events "FD_READ" and FD_WRITE
}
我不知道如何进一步进行。我该如何检查是否发生了任何所需的事件?我怎样才能不断地检查这些事件?那会在一些 while(1) 循环下吗?
我在互联网上找到的所有示例都是针对多个套接字的。但是,就我而言,我只有一个套接字,我想让它“事件驱动”以进行读写。请帮我。我被困住了!