Question about WSAAsync sockets

This is a discussion on Question about WSAAsync sockets within the Windows Programming forums, part of the Platform Specific Boards category; Hi, didnt really know to put this under networking or windows, but anyway here it goes. I was reading an ...

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    63

    Question about WSAAsync sockets

    Hi, didnt really know to put this under networking or windows, but anyway here it goes.
    I was reading an article on gamedev about async sockets and there was a section titled
    Re-enabling Functions
    The way WinSock handles messages is that it only posts one at a time. Once a message is posted, no other messages areposted until they are handled, and a re-enabling function is used.
    reference http://www.gamedev.net/reference/art...rticle1297.asp

    It wasnt exactly clear though on a couple of points. When FD_ Message is sent, lets just say FD_READ, does that mean all winsock messages including FD_WRITE and so on are also withheld (come to think of it, can anybody else think of another word in the english language with to hh next to each other?? lol) or just more FD_READ's.

    The other thing, and this will actually have an impact on me, if i have two sockets and one of them receives a FD_READ, will that block the other socket from sending FD_ messages.

    If so, is it acceptable to go send(wParam, nullbuffer, 0, 0) to get the next event?

  2. #2
    EOP
    EOP is offline
    Registered User
    Join Date
    Jan 2008
    Posts
    45
    All messages are queued.

    You have to catch the WM_WSAASYNC message:
    ON_MESSAGE( WM_WSAASYNC, &MyClass::OnSocketNotification )

    Handle it like this:
    Code:
    LRESULT MyClass::OnSocketNotification(WPARAM wParam, LPARAM lParam)
    {
    	WORD wEvent = WSAGETSELECTEVENT(lParam);
    	WORD wError = WSAGETSELECTERROR(lParam);
    	SOCKET hSock = (SOCKET)wParam;	// for which socket is this notification
    	if( wError )
    	{
    		// error handling
    	}
    	switch( wEvent )		// which event occurred for hsock
    	{
    		case FD_CONNECT:
    			// hsock is connected
    			break;
    		case FD_CLOSE:
    			// hsock is closed
    			break;
    		case FD_READ:
    			// hsock can start to recv
    			break;
    		case FD_WRITE:
    			// hsock can start to send
    		default:
    			break;
    	}
       return( 0L );
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sockets: IPv4 vs IPv6
    By ninboy in forum Networking/Device Communication
    Replies: 1
    Last Post: 10-15-2008, 01:02 AM
  2. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  3. Hi all!, Another question about socket's & NetBios
    By Pandora in forum Windows Programming
    Replies: 9
    Last Post: 03-19-2003, 07:10 AM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 08:22 PM
  5. Sockets Question
    By SyntaxBubble in forum Windows Programming
    Replies: 6
    Last Post: 12-30-2001, 06:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21