open method

  1. @override
Future<void> open({
  1. Duration? pingInterval,
})
override

Implementation

@override
Future<void> open({Duration? pingInterval}) async {
  final openAttempt = ++_openAttempt;
  _socket?.destroy();
  _socket = null;
  _messageLength = null;
  _upgradeRequested = false;
  _outboundBuffer = <Uint8List>[];
  _flatBuffersProfile = _serializer is flatbuffers.Serializer
      ? const flatbuffers.FlatBuffersSessionProfile.client()
      : null;
  _onDisconnect = Completer();
  _onConnectionLost = Completer();
  _handshakeCompleter = Completer();
  _inboundBuffer = Uint8List(0);
  _inboundFrameBuffer = null;
  _inboundFrameLength = 0;
  _goodbyeSent = false;
  _goodbyeReceived = false;
  try {
    final Socket socket;
    if (_ssl) {
      socket = await SecureSocket.connect(
        _host,
        _port,
        context: _tlsSecurityContext as SecurityContext?,
        onBadCertificate: (certificate) => _allowInsecureCertificates,
      );
    } else {
      socket = await Socket.connect(_host, _port);
    }
    if (openAttempt != _openAttempt) {
      socket.destroy();
      return;
    }
    _socket = socket;
    socket.setOption(SocketOption.tcpNoDelay, true);
    _pingInterval = pingInterval;
    unawaited(_runPingInterval());
    _sendInitialHandshake();
  } on SocketException catch (error) {
    if (openAttempt == _openAttempt && !_onConnectionLost!.isCompleted) {
      _onConnectionLost!.complete(error);
    }
  }
}