title: How do i judge when the NetWorkStream finishes by using .net TcpClient to communicate
body: <p>I try to use stream.DataAvailable to judge if it is finished,but sometimes the value is false but after a little while it is true again,i have to set a counter and judge the end by the symbol '>' like this </p>
  
  <pre><code>int connectCounter = 0;
  
  while (connectCounter &lt; 1200)
  {
      if (stream.DataAvailable)
      {
          while (stream.DataAvailable)
          {
              byte[] buffer = new byte[bufferSize];
              int flag = stream.Read(buffer, 0, buffer.Length);
              string strReadXML_t = System.Text.Encoding.Default.GetString(buffer);
              strReadXML = strReadXML + strReadXML_t.Replace("\0", string.Empty);       
          }
  
          if (strReadXML.Substring(strReadXML.Length - 1, 1).Equals("&gt;"))
          {
              break;
          }
      }
      Thread.Sleep(100);
      connectCounter++;
  }
  </code></pre>
  
  <p>is there any good methord to deal with it?Thank you!</p>