Get Length of Data Available in NetworkStream

前端 未结 4 1869
臣服心动
臣服心动 2020-12-04 01:54

I would like to be able to get the length of the data available from a TCP network stream in C# to set the size of the buffer before reading from the network stream. There i

4条回答
  •  被撕碎了的回忆
    2020-12-04 02:09

    You could send the lenght of the incoming data first. For example: You have data = byte[16] you want to send. So at first you send the 16 and define on the server, that this length is always 2 (because 16 has two characters). Now you know that the incomingLength = 16. You can wait now for data of the lenght incomingLength.

提交回复
热议问题