Future<RawSecureSocket> connect(host, int port, { SecurityContext context, bool onBadCertificate(X509Certificate certificate), List<String> supportedProtocols })

Constructs a new secure client socket and connect it to the given host on the given port. The returned Future is completed with the RawSecureSocket when it is connected and ready for subscription.

The certificate provided by the server is checked using the trusted certificates set in the SecurityContext object If a certificate and key are set on the client, using SecurityContext.useCertificateChain and SecurityContext.usePrivateKey, and the server asks for a client certificate, then that client certificate is sent to the server.

onBadCertificate is an optional handler for unverifiable certificates. The handler receives the X509Certificate, and can inspect it and decide (or let the user decide) whether to accept the connection or not. The handler should return true to continue the RawSecureSocket connection.

Source

static Future<RawSecureSocket> connect(
    host,
    int port,
    {SecurityContext context,
     bool onBadCertificate(X509Certificate certificate),
     List<String> supportedProtocols}) {
  _RawSecureSocket._verifyFields(
      host,
      port,
      false,
      false,
      false,
      onBadCertificate);
  return RawSocket.connect(host, port)
      .then((socket) {
        return secure(socket,
                      context: context,
                      onBadCertificate: onBadCertificate,
                      supportedProtocols: supportedProtocols);
      });
}