Udpclient asynchronous receive getting 1 packet every 2

erupter

Member
Joined
Jun 29, 2010
Messages
12
Programming Experience
1-3
Below you can find the complete code of a small test app.
It finds the main IP address, trys to find the related subnet mask, and from these two it gets a subnet broadcast address to use subsequently.
At each press of the "Send Dgrm" button, an unconnected UDP transmission is started.
At each press a packet is sent on the network (verified this with Wireshark packet sniffer). But my application shows a received packet only every 2 packet sent. I fail to understand why.
Hope someone can help me trace this.
 

Attachments

Last edited by a moderator:
You're starting an asynchronous BeginReceive, but do not read the result from EndReceive, instead you start a new synchronous Receive operation (then another BeginReceive). Strange that it works at all mixing modes like that, but that would be the explanation you only read every second packet.
 
You're starting an asynchronous BeginReceive, but do not read the result from EndReceive, instead you start a new synchronous Receive operation. Strange that it works at all mixing modes like that, but that would be the explanation you only read every second packet.

Thank you for taking the time to read through the code.
How should i fetch the data in async mode? I used the receive command due to lack of anything that seemed appropriate for the purpose.
There is the beginReceive which requires the callback function, but then there is no sub/delegate/property/whatever from which to read the buffer.
Or at least i could not find anything apart from Receive itself.

Update: ok stupid me!
In the exact same place, instead of calling _udpclient.Receive it should be _udpclient.endreceive(result, _receivingaddress)

Thank you very much!!!
It was right there but i could not find it :P
 
Last edited:
Back
Top