connect method Null safety

void connect(
  1. Socket socket,
  2. {ConnectionInfo? connectionInformation}
)
inherited

Starts to liste on socket.

This is mainly useful for testing purposes, ensure to set connectionInformation manually in this case.

Implementation

void connect(Socket socket, {ConnectionInfo? connectionInformation}) {
  if (connectionInformation != null) {
    connectionInfo = connectionInformation;
    _greetingsCompleter = Completer<ConnectionInfo>();
  }
  _socket = socket;
  _writeFuture = null;
  if (connectionTimeout != null) {
    final timeoutStream = socket.timeout(connectionTimeout!);
    _socketStreamSubscription = timeoutStream.listen(
      _onDataReceived,
      onDone: onConnectionDone,
      onError: _onConnectionError,
    );
  } else {
    _socketStreamSubscription = socket.listen(
      _onDataReceived,
      onDone: onConnectionDone,
      onError: _onConnectionError,
    );
  }
  _isConnected = true;
  isSocketClosingExpected = false;
}