protected override async Task OnClientMessageAsync(RfpConnection connection, ReadOnlyMemory <byte> data, CancellationToken cancellationToken) { if (data.Length >= 18 && data.Span.StartsWith(SysInit.Span)) { _connections.AddOrUpdate(connection.Identifier, connection, (m, c) => connection); } foreach (var subscription in _subscriptions.Values.OrderBy(x => x.Priority)) { try { data = await subscription.OnRfpMessageAsync(connection.Identifier, data, cancellationToken).ConfigureAwait(false); } catch (Exception ex) { Console.WriteLine(ex.Message); _subscriptions.TryRemove(subscription, out _); try { subscription.Cancel(); } catch (ObjectDisposedException) {} } } if (!data.IsEmpty) { await connection.SendToServerAsync(data, cancellationToken).ConfigureAwait(false); } }
protected override async Task OnServerMessageAsync(RfpConnection connection, ReadOnlyMemory <byte> data, CancellationToken cancellationToken) { foreach (var subscription in _subscriptions.Values.OrderBy(x => x.Priority)) { try { data = await subscription.OnOmmMessageAsync(connection.Identifier, data, cancellationToken) .ConfigureAwait(false); } catch (Exception ex) { Console.WriteLine(ex.Message); _subscriptions.TryRemove(subscription, out _); try { subscription.Cancel(); } catch (ObjectDisposedException) {} } } if (!data.IsEmpty) { await connection.SendToClientAsync(data, cancellationToken).ConfigureAwait(false); } }
protected abstract Task OnServerMessageAsync(RfpConnection connection, ReadOnlyMemory <byte> data, CancellationToken cancellationToken);