I've noticed that there are several ways of sending data through a TCP stream. I want to do it the fastest way in terms of latency.One method I became aware of is with a binary writer:using (MemoryStream ms = PrintWindow(process)){    writer.Write((int)ms.Length);    writer.Write(ms.GetBuffer(), 0, (int)ms.Length);}And to receive it:Image.FromStream(new MemoryStream(reader.ReadBytes(reader.ReadInt32())));It writes the size for reference, then takes the data.For the other method, which is a bit sensitive, it seems that it can easily fail if the image changes for some reason:using (MemoryStream ms = PrintWindow(process)){        tcp.GetStream().Write(ms.GetBuffer(), 0, tcp.SendBufferSize); }And to receive it:byte[] b = new byte[tt1.ReceiveBufferSize];tt1.GetStream().Read(b, 0, tt1.ReceiveBufferSize);Image.FromStream(new MemoryStream(b));I've found this with trial and error.  But, as I've said, it's very sensitive and can cause an error if the image changes in a certain way.  I'm not absolutely sure why, though.Which of these is the fastest?  In my view, writing with just the stream should be faster than with some special writer.The error I get when using the second method seems to occur when the data is very low.  For example: a black or near-black picture. If anyone knows how to solve this, please let me know.It seems that I need to have the TCP Send and Receive buffer at least as big as the largest file for it to work, so I've increased it by x128.  I'm not sure if that's a good idea or not, but from my understanding, the only thing it does is allocate more RAM.  Then again, I think it's probably because I set the byte size to the buffer size.
Sending data through a TCP stream
c#;comparative review;stream;tcp