I use the network protocol built around TcpClient, using BinaryReaderto read bytes from the base NetworkStream(and vice versa, using BinaryWriterto write).
The protocol transmits strings in UTF-8 encoding and calls it reader.ReadString()for reading from the stream (using writer.Write(someStr)for writing).
Is there an easy way to determine the number of bytes read (or written) in a NetworkStream without having to jump through hoops to calculate the actual byte lengths of the transmitted strings?
Note that it BinaryWriter.Write()writes an integer with 7-bit encoding before the actual bytes of the string, which makes any manual calculation extra complicated.
Also note that it NetworkStreamdoes not support the property Position, as it complains of impossibility Seek.
In addition, I would like to avoid introducing intermediaries who must copy / scan data into the read / write process so as not to affect the performance of the entire system.
Is there a simple, high-level way to count bytes passing through a network interface without having to manually consider the encoding and string length?
source
share