startConnect 静态方法

Future<ConnectionTask<SecureSocket>> startConnect(
  1. dynamic host,
  2. int port, {
  3. SecurityContext? context,
  4. bool onBadCertificate(
    1. X509Certificate certificate
    )?,
  5. void keyLog(
    1. String line
    )?,
  6. List<String>? supportedProtocols,
})
override

connect 类似,但返回一个 Future,当 SecureSocket 不再需要时可以取消此连接任务。

实现

static Future<ConnectionTask<SecureSocket>> startConnect(host, int port,
    {SecurityContext? context,
    bool onBadCertificate(X509Certificate certificate)?,
    void keyLog(String line)?,
    List<String>? supportedProtocols}) {
  return RawSecureSocket.startConnect(host, port,
          context: context,
          onBadCertificate: onBadCertificate,
          keyLog: keyLog,
          supportedProtocols: supportedProtocols)
      .then((rawState) {
    Future<SecureSocket> socket =
        rawState.socket.then((rawSocket) => new SecureSocket._(rawSocket));
    return new ConnectionTask<SecureSocket>._(socket, rawState._onCancel);
  });
}