private async Task CheckClients(CancellationToken ct) { while (!ct.IsCancellationRequested) { Connection key = null; foreach (var connection in _connections) { if (!connection.Value.IsConnected()) { key = connection.Value; } } if (key != null) { _connections.TryRemove(key.ClientId, out var conn); if (conn != null) { await _dispatcher.Execute(new DisconnectMessage(), conn); } } await Task.Delay(200, ct); } }
internal async Task ProcessCommandsAsync(CancellationToken ct) { while (!ct.IsCancellationRequested) { try { var command = await _transport.ReadCommandAsync(ct); if (command != null) { if (!AuthorizedForReceive && !(command.Payload is InitiateHandshakeMessage)) { await Send(new NotAuthorizedMessage("You are not authorized to send messages")); continue; } await SendReceiveConfirmation(command); await _dispatcher.Execute(command.Payload, this); await SendHandledConfirmation(command); } Thread.Sleep(5); } catch (IOException) { break; } } Dispose(); }