Click here to Skip to main content
11,630,144 members (80,340 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C Windows Visual-Studio Events , +
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? Frown | :(

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

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 9-May-13 23:26pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS


Advertise | Privacy | Mobile
Web03 | 2.8.150723.1 | Last Updated 10 May 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100