description

# connect method Null safety

Future<SecureSocket> connect (

1. dynamic host,
2. int port,
3. {SecurityContext? context,
4. bool onBadCertificate(
   1. X509Certificate certificate
   ),
5. List<String>? supportedProtocols,
6. Duration? timeout}

)
override

Constructs a new secure client socket and connects it to the given `host` on port `port`. The returned Future will complete with a SecureSocket that is connected and ready for subscription.

The certificate provided by the server is checked using the trusted certificates set in the SecurityContext object. The default SecurityContext object contains a built-in set of trusted root certificates for well-known certificate authorities.

`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 SecureSocket connection.

`supportedProtocols` is an optional list of protocols (in decreasing order of preference) to use during the ALPN protocol negotiation with the server. Example values are "http/1.1" or "h2". The selected protocol can be obtained via SecureSocket.selectedProtocol.

The argument `timeout` is used to specify the maximum allowed time to wait for a connection to be established. If `timeout` is longer than the system level timeout duration, a timeout may occur sooner than specified in `timeout`. On timeout, a SocketException is thrown and all ongoing connection attempts to `host` are cancelled.

## Implementation

    static Future<SecureSocket> connect(host, int port,
        {SecurityContext? context,
        bool onBadCertificate(X509Certificate certificate)?,
        List<String>? supportedProtocols,
        Duration? timeout}) {
      return RawSecureSocket.connect(host, port,
              context: context,
              onBadCertificate: onBadCertificate,
              supportedProtocols: supportedProtocols,
              timeout: timeout)
          .then((rawSocket) => new SecureSocket._(rawSocket));
    }