title: How to read unknown data length in a TCP Client
body: <p>I am relativity new to C#. In my TCP client have the following function which sends data to the server and returns the response:</p>
  
  <pre><code>private static TcpClient tcpint = new TcpClient(); //Already initiated and set up
  private static NetworkStream stm;                  //Already initiated and set up
  
  private static String send(String data)
  {
      //Send data to the server
      ASCIIEncoding asen = new ASCIIEncoding();
      byte[] ba = asen.GetBytes(data);
      stm.Write(ba, 0, ba.Length);
  
      //Read data from the server
      byte[] bb = new byte[100];
      int k = stm.Read(bb, 0, 100);
  
      //Construct the response from byte array to string
      StringBuilder sb = new StringBuilder();
      for (int i = 0; i &lt; k; i++)
      {
          sb.Append(bb[i].ToString());
      }
  
      //Return server response
      return sb.ToString();
  }
  </code></pre>
  
  <p>As you can see here, when I am reading the response from the server, I am reading it into a fix byte[] array of length 100 bytes.</p>
  
  <pre><code>byte[] bb = new byte[100];
  int k = stm.Read(bb, 0, 100);
  </code></pre>
  
  <p>What do i do if the response from the server is more than 100 bytes? How can I read the data without me knowing what the max length of data form the server will be?</p>