Asynchronous ReceiveCallback method question

Bines

New member
Joined
Aug 29, 2007
Messages
3
Programming Experience
Beginner
The MSDN article entitled “Using an Asynchronous Client Socket” says the following:

'The receive callback method ReceiveCallback implements the AsyncCallback delegate. It receives the data from the network device and builds a message string. It reads one or more bytes of data from the network into the data buffer and then calls the BeginReceive method again until the data sent by the client (surely this should be server?) is complete. Once all the data is read from the client (server?), ReceiveCallback signals the application thread that the data is complete by setting the ManualResetEvent sendDone (receiveDone?).' (I think whoever wrote this used some cut-and-paste from the 'send' description and forgot to adjust the text)

Can someone please tell me HOW the BeginReceive method knows that the data sent by the server is complete. I’m experimenting with a small client which receives seven bytes from a particular server (which is the expected number) but never signals that the read is complete - so my program blocks and I can’t send the result to the screen nor do anything else. My code is based on the examples given in the article.

Any help would be very much appreciated.
 
Back
Top