listen function

bool listen(
  1. Function onData
)

Starts listening on the socket for packets sent by the RCON server. Returns a boolean that specifies if the socket has started listening. Note: onData must accept a List

Implementation

bool listen(Function onData) {
  // Checks to ensure that the RCON socket exists.
  if (rconSck == null) {
    return false;
  }

  // Starts listening on the RCON socket.
  // Calls the first handler if we receive data, calls onError
  // if there is an error on the stream, calls onDone when the
  // client or the server ends the connection.
  rconSck!.listen(
    (Uint8List data) {
      pSR(data, onData);
    },
    onError: (error) {
      print('mc_rcon: Error with the connection to the server: $error');
      rconSck!.destroy();
    },
    onDone: () {
      print('mc_rcon: The server has ended the connection.');
      rconSck!.destroy();
    },
    cancelOnError: false,
  );

  return true;
}