This class is uses Microsoft's implementation of SSL. Most of the code is copied from: http://msdn.microsoft.com/en-us/library/system.net.security.sslstream%28v=vs.110%29.aspx
        public HttpConnection openConnection(string address, int port)
        {
            HttpConnection thisConnection;
            try
            {
                TcpClient client = new TcpClient();

                client.Connect(address, port);

                thisConnection = new HttpConnection(address, port, address, client.GetStream());
            }
            catch (SocketException se)
            {
                throw new NetworkException("Stream cannot be opened. Socket error " + se.ToString());
            }

            return thisConnection;
        }
        // in the fure HttpConnections can have some form of callback or events that will register with the entity
        public HttpConnection openSecureConnection(string address, int port, string servername)
        {
            HttpConnection thisConnection;
            try
            {
                TcpClient client = new TcpClient(address, port);
                RemoteCertificateValidationCallback call_bk = ValidateServerCertificate;
                if (this.UNSECURE)
                {
                    call_bk = ValidateServerCertificate_insecure;
                }
                SslStream sslStream = new SslStream(
                    client.GetStream(),
                    false,
                    new RemoteCertificateValidationCallback(call_bk),
                    null
                    );
                // The server name must match the name on the server certificate.
                sslStream.AuthenticateAsClient(servername); // may throw AuthenticationException
                thisConnection = new HttpConnection(address, port, servername, sslStream);
            }
            catch (SocketException se)
            {
                throw new NetworkException("SSL: Stream cannot be opened. Socket error " + se.ToString());
            }
            catch (IOException se)
            {
                throw new NetworkException("SSL: Stream cannot be opened. Socket error " + se.ToString());
            }

            return thisConnection;
        }