title: Calling Node.js service via C# when the response size is unknown
body: <p>I have some C# that is successfully calling my TCP service (running on Node.js) and receiving a response.  My code looks similar to this:</p>
  
  <pre><code>string html = Console.ReadLine();
  Byte[] htmlBytes = System.Text.Encoding.ASCII.GetBytes(html);
  
  TcpClient client = new TcpClient("127.0.0.1", 5000);
  NetworkStream stream = client.GetStream();
  stream.Write(htmlBytes, 0, htmlBytes.Length);
  Console.WriteLine("Message has been sent");
  
  Byte[] responseBytes = new Byte[50000];
  int numberOfBytes = stream.Read(responseBytes, 0, responseBytes.Length);
  </code></pre>
  
  <p>My questions is in regarding to this code:</p>
  
  <pre><code>Byte[] responseBytes = new Byte[50000];
  int numberOfBytes = stream.Read(responseBytes, 0, responseBytes.Length);
  </code></pre>
  
  <p>Because <code>responseBytes</code> is passed by reference into <code>stream.Read(...)</code>, it must be initialized, so I've chosen a size of 50000.  If the response is more than 50000, then I only receive the first 50000 bytes.</p>
  
  <p>This works fine if my response is 50000 bytes or smaller, but what if I don't know what the response size will be?  Is there a best practice for receiving large responses or handling a situation where the byte array returned is unknown?</p>