Re: Asynchronous UDP Sockets ~ No Read events!
From: Alexander Nickolov (agnickolov_at_mvps.org)
Date: 10/26/04
- Next message: Dan Mitchell: "Re: Listening port -> process ID?"
- Previous message: Man Lee: "Asynchronous UDP Sockets ~ No Read events!"
- In reply to: Man Lee: "Asynchronous UDP Sockets ~ No Read events!"
- Next in thread: Man Lee: "Re: Asynchronous UDP Sockets ~ No Read events!"
- Reply: Man Lee: "Re: Asynchronous UDP Sockets ~ No Read events!"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 26 Oct 2004 09:59:01 -0700
First, I hope all your if-s fall through - do not continue. Otherwise
you'll miss multiple notifications delivered with a single event.
Second, by clearing your event explicitly you create a race condition
and can miss notifications. WSAEnumNetworkEvents already
does this for you, so take out your explicit reset.
-- ===================================== Alexander Nickolov Microsoft MVP [VC], MCSD email: agnickolov@mvps.org MVP VC FAQ: http://www.mvps.org/vcfaq ===================================== "Man Lee" <noreply@this.address.com> wrote in message news:OZU4Mb3uEHA.4028@TK2MSFTNGP15.phx.gbl... > Hi all, > > I have a UDP client set up asynchronously. > I never get any FD_READ events. > Just curious if I'm missing something... > > Here is what I have: > > Using Winsock 2.2 on XP via VS2003 > In a thread I have the following loop: > > SOCKET s = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); > bind(s, (struct sockaddr*)&my_addr, sizeof(my_addr)); > WSAEventSelect(s, hEvent, FD_READ | FD_WRITE | FD_CONNECT | FD_CLOSE); > while (1) > { > //Error checking codes are removed > > WSAWaitForMultipleEvents(1, pEvents, FALSE, 30000, FALSE); > > WSANETWORKEVENTS NetworkEvents = {0}; > WSAEnumNetworkEvents(s, hEvent, &NetworkEvents); > > if (NetworkEvents.lNetworkEvents & FD_CONNECT) > { > // Notify a Connect Event > // This fires!!! > // When I call connect via UDP > } > > if (NetworkEvents.lNetworkEvents & FD_READ) > { > // Notify a Read Event > // Nothing ever happens... :( > } > > if (NetworkEvents.lNetworkEvents & FD_WRITE) > { > // Notify a Write Event > > // This fires!!! > // When immediately to signal I am able to send. > } > > if (NetworkEvents.lNetworkEvents & FD_CLOSE) > { > // Notify a Close Event > // I don't think this will actually ever happen for a UDP socket > // But it is here for the heck of it... > } > > WSAResetEvent(hEvent); > > // There is some logic here to exit the loop when necessary that is > removed... > } > > As the comments above say, the FD_CONNECT and FD_WRITE events fire. > So I am poisitive that there is nothing wrong in how I use > WSAEventSelect() > and its sibiling methods. > > Here is what takes the cake: > When the above code is used against a TCP connection, it works fine, > FD_READ fires accordingly. > > When the above code is used against a UDP socket, it doesn't work. > BUT, when I direct my client to send packets to itself, the FD_READ does > fires! > It only doesn't fire when packets arrive from another computer. > I snoop my incoming data and can confirm packets are being recv'ed by my > NIC > from the other computer. > So, the packets are there, but the event is not firing... > > There are also no errors being returned in the loop, so that is not the > issue. > I have a feeling it has to do with some strange network setup that is on > my > computer... > > Does any one have similiar problems? > If so, how can it be resolved? > > Thanks for any help! > -man. > >
- Next message: Dan Mitchell: "Re: Listening port -> process ID?"
- Previous message: Man Lee: "Asynchronous UDP Sockets ~ No Read events!"
- In reply to: Man Lee: "Asynchronous UDP Sockets ~ No Read events!"
- Next in thread: Man Lee: "Re: Asynchronous UDP Sockets ~ No Read events!"
- Reply: Man Lee: "Re: Asynchronous UDP Sockets ~ No Read events!"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|