Click here to Skip to main content
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 10-May-13 0:26am

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
0 Sergey Alexandrovich Kryukov 565
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 10 May 2013
Copyright © CodeProject, 1999-2014
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