If this is a TCP based stream, then the answer is that the rest of the data simply didn't arrive yet.
TCP is stream oriented. That means there is no relation between the number of Send
/Write
calls, and the number of receive events. Multiple writes can be combined together, and single writes can be split.
If you want to work with messages on TCP, you need to implement your own packeting algorithm on top of it. Typical strategies to achieve this are:
- Prefix each packed by its length, usual with binary data
- Use a separation sequence such as a line-break. Usual with text data.
If you want to read all data in a blocking way you can use loop until DataAvailable
is true
but a subsequent call to Read
returns 0
. (Hope I remembered that part correctly, haven't done any network programming in a while)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…