title: Connecting to IMAP via StreamSocket in WinRT / C#
body: <p>Trying to write a simple bit of code to connect to an IMAP server using StreamSocket. It reads the server connect response, but then it won't read anything else. </p>
  
  <pre><code>    private async void TCPTest(string hostName, string port)
      {
          status.Text = "start of TCPTest";
  
          StreamSocket socket = new StreamSocket();
          await socket.ConnectAsync(new HostName(hostName), port);
  
          string senddata = "A001 login uuu ppp";
  
          status.Text += "\n first reading...";
          DataReader reader = new DataReader(socket.InputStream);
          reader.InputStreamOptions = InputStreamOptions.Partial;
          await reader.LoadAsync(1024);
          string data = reader.ReadString(reader.UnconsumedBufferLength);
          status.Text += "\n &gt; read " + data;
  
          status.Text += "\n writing...";
          writer = new DataWriter(socket.OutputStream);
          writer.WriteString(senddata);
          await writer.StoreAsync();
          status.Text += "\n &gt; wrote " + sendata;
  
          status.Text += "\n second reading...";
          writer = new DataWriter(socket.OutputStream);
          await reader.LoadAsync(1024);
          string data2 = reader.ReadString(reader.UnconsumedBufferLength);
          status.Text += "\n &gt;" + data2;
  
          status.Text += "\n end of TCPTest";
      }
  </code></pre>
  
  <p>This is the output I get. </p>
  
  <pre><code>start of TCPTest
  first reading...
  &gt; read * OK mydomain.com IMAP4rev1 MDaemon 13.0.1 ready
  writing...
  &gt; wrote A001 login uuu ppp
  second reading... 
  </code></pre>
  
  <p>The app never gets any further than this. There's no error, it just hangs. Am I doing something fundamentally wrong here? My code is the same (more or less) as the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj150599.aspx" rel="nofollow">StreamSocket example on MSDN</a></p>