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

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

    Also I troubled same problem.

    When I tested several times, I found that sometimes multiple BeginReceive - EndReceive makes packet loss. (This loop was ended improperly)

    In my case, I used two solution.

    First, I defined the enough packet size to make only 1 time BeginReceive() ~ EndReceive();

    Second, When I receive large size of data, I used NetworkStream.Read() instead of BeginReceive() - EndReceive().

    Asynchronous socket is not easy to use, and it need a lot of understanding about socket.

提交回复
热议问题