Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am working on newtwork event based socket application.

When client has sent some data and there is something to be read on the socket, FD_READ network event is generated.

Now according to my understanding, when server wants to write over the socket, there must be an event generated i.e. FD_WRITE. But how this message will be generated?

When there is something available to be read, FD_READ is automatically generated but what about FD_WRITE when server wants to write something? :(

Anyone who can help me with this confusion please? :(

Following is the code snippet:

WSAEVENT hEvent = WSACreateEvent();
WSANETWORKEVENTS events;
WSAEventSelect(newSocketIdentifier, hEvent, FD_READ | FD_WRITE);

   while(1)
      {   //while(1) starts
         waitRet = WSAWaitForMultipleEvents(1, &hEvent, FALSE, WSA_INFINITE, FALSE);
		 //WSAResetEvent(hEvent);
         if(WSAEnumNetworkEvents(newSocketIdentifier,hEvent,&events) == SOCKET_ERROR)
                {
                  //Failure
	        }
	 else
		{   //else event occurred starts
		    if(events.lNetworkEvents & FD_READ)
			{
                            //recvfrom()   
			}
		    if(events.lNetworkEvents & FD_WRITE)
			{
				 //sendto()
			}
		}
      }
Posted

1 solution

See http://msdn.microsoft.com/en-us/library/windows/desktop/ms741540(v=vs.85).aspx[^] for a complete description of how these events are generated and consumed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900