private async void Heartbeat() { while (!_cancellationToken.IsCancellationRequested) { await Task.Delay(3000); if (_cancellationToken.IsCancellationRequested) { return; } var keepAlivePacket = new CommandNetworkRequest(""); Send(keepAlivePacket); keepAlivePacket.WaitUntilAcknowledged(5000); if (!keepAlivePacket.Acknowledged) { try { Disconnected?.Invoke(this, new EventArgs()); } catch { } } } }
/// <summary> /// Sends a raw string command to the rcon server. /// </summary> /// <param name="command">Command string to send</param> /// <returns><see cref="CommandNetworkRequest"/> which will be acknowledged by the rcon server and (if sent by the rcon server) contain the response string.</returns> public CommandNetworkRequest Send(string command) { var request = new CommandNetworkRequest(command); _networkConnection?.Send(request); return(request); }