How much buffer does NetworkStream and TcpClient have?

Earlz picture Earlz · Mar 28, 2010 · Viewed 17.9k times · Source

We are writing a TCPServer and Client program. How much space is there in the TcpClient buffer? Like, at what point will it begin to throw away data? We are trying to determine if the TcpClient can be blocking or if it should go into it's own background thread(so that the buffer can not get full)..

Answer

nos picture nos · Mar 28, 2010

You can get the buffer sizes from TcpClient.ReceiveBufferSize and TcpClient.SendBufferSize .

The available buffer sizes will vary as data is received/acknowledged(or not) at the TCP level. TcpClient is blocking by default.

No data will be thrown away as a result of full buffers, though data could be throw away in under error conditions (such as the peer disappears/crashes/exits etc.)