Copying NetworkStream to MemoryStream takes infitity ∞ days

后端 未结 3 649
被撕碎了的回忆
被撕碎了的回忆 2021-01-20 04:54

I\'ve following code:

_clientRequestStream = _tcpClient.GetStream();

var memoryStream = new MemoryStream();
_clientRequestStream.CopyTo(memoryStream);
         


        
3条回答
  •  忘掉有多难
    2021-01-20 05:32

    TCP is a stream protocol. Bytes can flow at an arbitrary rate. Theoretically you could get one byte, then several seconds later 10 bytes, then several minutes later two bytes.

    TCP is useless as a protocol in and of itself.

    There must be a higher-order protocol whose structure allows for the detection of both the beginning and the end of a "message". We cannot guess at what higher-order protocol you are listening to, you have to know that in order to listen.

提交回复
热议问题