Exemple #1
0
        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);
            }
        }
Exemple #2
0
 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);
     }
 }
Exemple #3
0
 protected abstract Task OnServerMessageAsync(RfpConnection connection, ReadOnlyMemory <byte> data, CancellationToken cancellationToken);