title: .NET SslStream is not working
body: <p>I am trying inialise a tls tunnel with the .net SslStream but after opening the stream I always get the following error:</p>
  
  <p>"Unable to read data from the transport connection: An established connection was aborted by the software in your host machine."</p>
  
  <p>After I establish a tls connection and after sending a second message. </p>
  
  <p>I've been searching for an answer for the last four days but there isn't any helpful information online! </p>
  
  <p>edit: 
  I am trying to connect to talk.google.com </p>
  
  <p>and I'm using the code sample from MSDN. Only difference is that I'm sending data before and when it is time to use tls i do the following: </p>
  
  <pre><code>public void SecureStream()
          {
          netStream.Flush();
          sslStream = new SslStream(netStream, false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
  
      sslStream.AuthenticateAsClient("talk.google.com");}
  </code></pre>
  
  <p>edit: I managed to eliminate the first error (small bug on how i was handling the send) now I always get </p>
  
  <p>"Unable to read data from the transport connection: An established connection was aborted by the software in your host machine."</p>
  
  <p>edit2: Im not sending any whitespaces I rewrote the message passing part and I still have the same problem. </p>
  
  <p>I start with </p>
  
  <pre><code>   String streamInit = "&lt;stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' to='google.com' version='1.0'&gt;";
          client.Send(streamInit);
  </code></pre>
  
  <p>Then on receive I have the following </p>
  
  <pre><code>  static void client_MessageReceived(SyncronousClient source, string Result)
      {
  
  
          if (Regex.IsMatch(Result, "&lt;starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"&gt;&lt;required/&gt;&lt;/starttls&gt;"))
          {
              String startTlS = "&lt;starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/&gt;";
              source.Send(startTlS);
  
          }
          else if (Regex.IsMatch(Result, "&lt;proceed xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/&gt;"))
          {
              //Do TLS Magic 
              source.SecureStream();
              String streamReInit = "&lt;stream:stream xmlns='jabber:client'xmlns:stream='http://etherx.jabber.org/streams'to='google.com'version='1.0'&gt;";
              source.Send(streamReInit);
          }
          else if (Regex.IsMatch(Result, "&lt;mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"&gt;"))
          {
              //String AuthType = "&lt;auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='X-GOOGLE-TOKEN'/&gt;";
              String AuthType = "&lt;auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"PLAIN\"/&gt;";
              source.Send(AuthType);
          }}
  </code></pre>