Exemplo n.º 1
0
        private async Task ConnectionLoop(Connection connection)
        {
            var transport = connection.ProcedureTransport;

            try
            {
                while (!cancellationTokenSource.Token.IsCancellationRequested)
                {
                    int magicNumber = await transport.ReadInt32();

                    Debug.Assert(Message.MagicNumber == magicNumber);
                    Message.Type messageType = (Message.Type) await transport.ReadInt32();

                    Debug.Assert(Message.Type.Method == messageType);
                    await _dispatcher.Dispatch(transport);
                }
            }
            catch (OperationCanceledException) { }
            catch (System.IO.IOException) { }

            connection.ProcedureTransport.Close();
            connection.EventTransport?.Close();
            _clients.TryRemove(connection.ID, out var _);
            OnClientDisconnection?.Invoke(connection.Info);
        }
Exemplo n.º 2
0
 public void RaiseClientDisconnectedEvent() => OnClientDisconnection?.Invoke(this);