connect method

  1. @mustCallSuper
Future<void> connect(
  1. String token
)

Connects to the server.

Implementation

@mustCallSuper
Future<void> connect(String token) async {
  await bind();
  _clientSalt = generateSalt();

  packets.listen((packet) {
    _connectionTimeout?.cancel();
    _connectionTimeout = Timer(const Duration(seconds: 5), () {
      logger.detail('Connection timed out');
      _cleanup();
    });
  });

  _connectionState = ConnectionState.sendingConnectionRequest;
  _connectionTimeout = Timer(const Duration(seconds: 5), () {
    if (_connectionState == ConnectionState.sendingConnectionRequest) {
      logger.detail('Connection timed out');
      _cleanup();
    }
  });
  _repeatSendingState(token);
}