Why do we need Reader/Writer Streams while Using TCPListner in C# networking?
example :
TcpClient client = server.AcceptTcpClient(); client.ReceiveTimeout = 75000; Stream s = client.GetStream(); StreamReader reader = new StreamReader(s); StreamWriter writer = new StreamWriter(s); writer.AutoFlush = true;
You only need
StreamReader/StreamWriterif you want to deal with text instead of binary data.Sockets deal with binary data naturally, which is why
TcpClientexposes a Stream. Stream is a binary abstraction, hence its Read/Write methods deal in byte arrays.TextReader/TextWriter(from whichStreamReader/StreamWriterare derived) deal with text – their methods deal with strings and char arrays.StreamReader/StreamWriterbasically wrap a stream and do the conversion (via anEncoding) between text and binary data for you.