title: Read contents from SslStream
body: <p>I have an application using which I execute IMAP commands using:</p>
  
  <ul>
  <li><code>TcpClient</code> to connect to the IMAP server</li>
  <li><code>SslStream</code> to write and read commands</li>
  </ul>
  
  <p>Problem:</p>
  
  <ul>
  <li>Cannot read the complete ouput content from the stream</li>
  <li><code>while</code> loop on the <code>SslStream.Read</code> seems not to work</li>
  <li><code>StreamReader.ReadLine</code>, <code>ReadToEnd</code>, <code>Read</code> methods do not work</li>
  </ul>
  
  <p>Sample code:</p>
  
  <pre><code>while ((l = reader.ReadLine()) != null)
  {
      output.AppendLine(l);
  }
  </code></pre>
  
  <p>This code snippet would read 1 to 2 lines and hang in <code>reader.Readline()</code>.</p>
  
  <p>Workaround I tried with setting the <code>ReadTimeout</code> property:</p>
  
  <pre><code>try
  {
      _output=new byte[_tcpclient.ReceiveBufferSize];
      _sslstream.Read(_output, 0, _output.Length);
      textBox1.Text = Encoding.ASCII.GetString(_output);
  }
  catch (IOException ex)
  {
      textBox1.Text ="ERROR !! " + ex.Message;                
  }
  </code></pre>
  
  <p>Help:</p>
  
  <ul>
  <li>How can I read the complete output of a command from the stream?</li>
  </ul>
  
  <p>Note: I do not want to use any third party libraries.</p>