title: C# read all bytes
body: <p>I am trying to write a simple client/server application in C#. The following is an example server reply sent to my client:</p>
  
  <pre><code>reply {20}&lt;entry name="test"/&gt;
  </code></pre>
  
  <p>where {20} indicates number of chars that full reply contains. 
  In the code I wrote below how can I use this number to loop and read ALL chars? </p>
  
  <pre><code>TcpClient tcpClient = new TcpClient(host, port);
  
  NetworkStream networkStream = tcpClient.GetStream();
  
  ...
  
  // Server Reply
  if (networkStream.CanRead)
  {
      // Buffer to store the response bytes.
      byte[] readBuffer = new byte[tcpClient.ReceiveBufferSize];
  
      // String that will contain full server reply
      StringBuilder fullServerReply = new StringBuilder();
  
      int numberOfBytesRead = 0;
  
      do
      {
          numberOfBytesRead = networkStream.Read(readBuffer, 0, readBuffer.Length);
          fullServerReply.AppendFormat("{0}", Encoding.UTF8.GetString(readBuffer, 0, tcpClient.ReceiveBufferSize));
      } while (networkStream.DataAvailable);
  }
  </code></pre>