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

后端 未结 7 1408
梦谈多话
梦谈多话 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

    You would read the length prefix first. Once you have that, you would just keep reading the bytes in blocks (and you can do this async, as you surmised) until you have exhausted the number of bytes you know are coming in off the wire.

    Note that at some point, when reading the last block you won't want to read the full 1024 bytes, depending on what the length-prefix says the total is, and how many bytes you have read.

提交回复
热议问题