So for awhile I’ve been using a StreamReader/Writer as a wrapper over a TcpClient’s NetworkStream – Mainly just for simplicity, and to save time.
It’s worked fine when working with a streamreader/writer on both ends of the connection, but i’ve noticed that when using one of these helper classes with a endpoint that is not also using the helper counterpart, strange things start happening. Extraneous bytes prepended to the stream and other weird things.
This has got me thinking, maybe there is some un-needed overhead with using these wrappers? or possibly compatibility issues when developing clients in other languages like C++ or PHP.
What are the implications of using the StreamReader and StreamWriter helper classes, and are there any benefits? (along the line of error handling or anything else)
StreamReader/Writer are letting you easily store/read text data to/from stream. There is no additional overhead on top of what they are for – convert values to text representation in correct encoding. There should be no problem consuming this text stream from other languages as long as both sides agree on encoding – i.e. one is default UTF-8 with BOM.
“Extraneous bytes prepended” is Byte Order Mark (BOM), which you can turn off when constructing the reader (and it is only for Unicode UTF-8/7/16 encoding).
Depending on your goals using raw streams for binary communication may be better/faster.