sendData method

Future<void> sendData(
  1. ClientPacket message
)

Implementation

Future<void> sendData(ClientPacket message) async {
  if (_socket == null) {
    _log.warning('Socket not connected, saving to Blackbox');
    final store = onBlackboxStore;
    if (store == null) {
      _log.warning('No Blackbox store callback, ignoring message');
      return;
    }
    await store(message.toPacket());
    _log.info('Saved to Blackbox');
    return;
  }

  final packet = message.toPacket();
  try {
    _socket?.writeln(packet);
  } catch (e) {
    _log.severe('Error sending packet: $packet - $e');
    await disconnect();
  }

  _flushBlackbox();
}