C# Begin/EndReceive - how do I read large data?

后端 未结 7 1411
梦谈多话
梦谈多话 2020-11-30 05:59

When reading data in chunks of say, 1024, how do I continue to read from a socket that receives a message bigger than 1024 bytes until there is no data left? Should I just u

7条回答
  •  眼角桃花
    2020-11-30 06:38

    No - call BeginReceive again from the callback handler, until EndReceive returns 0. Basically, you should keep on receiving asynchronously, assuming you want the fullest benefit of asynchronous IO.

    If you look at the MSDN page for Socket.BeginReceive you'll see an example of this. (Admittedly it's not as easy to follow as it might be.)

提交回复
热议问题