Exemplo n.º 1
0
 private async Task ReadClientMessages(ClientConnection connection)
 {
     while (!cancellation.IsCancellationRequested)
     {
         var message = await connection.ReadMessage();
         OnIncomingMessage(new IncomingMessage(connection, message));
     }
 }
Exemplo n.º 2
0
        private void OnClientAccepted(Socket clientSocket)
        {
            var clientConnection = new ClientConnection(clientSocket);

            var clientAcceptedHandlers = ClientAccepted;
            if (clientAcceptedHandlers != null)
                clientAcceptedHandlers(this, clientConnection);
        }
Exemplo n.º 3
0
 private async void ClientDisconnected(object sender, ClientConnection connection)
 {
     try
     {
         await BroadcastToAll(new Message { Sender = "<server>", Text = $"{connection} disconnected" });
     }
     catch (Exception ex)
     {
         logger.Warn(ex, "{0} disconnected handling", connection);
     }
 }
Exemplo n.º 4
0
        private async void OnClientAccepted(object sender, ClientConnection connection)
        {
            ImmutableInterlocked.Update(ref clients, oldClients => oldClients.Add(connection));
            logger.Debug("{0} connected", connection);
            OnClientConnected(connection);

            try
            {
                await ReadClientMessages(connection);
            }
            catch (Exception ex)
            {
                if (ex is OperationCanceledException || ex is DisconnectedException) { }
                else { logger.Warn(ex, "{0} disconnected with error", connection); }
            }
            finally
            {
                ImmutableInterlocked.Update(ref clients, oldClients => oldClients.Remove(connection));
                logger.Debug("{0} disconnected", connection);
                OnClientDisconnected(connection);
            }
        }
Exemplo n.º 5
0
 public IncomingMessage(ClientConnection sender, Message message)
 {
     Sender = sender;
     Message = message;
 }
Exemplo n.º 6
0
 private void OnClientDisconnected(ClientConnection connection)
 {
     var handlers = ClientDisconnected;
     if (handlers != null) { handlers(this, connection); }
 }
Exemplo n.º 7
0
 public async Task ReplyTo(ClientConnection client, Message message)
 {
     await Task.Yield();
     await client.SendMessage(message);
 }
Exemplo n.º 8
0
        public async Task ReplyTo(ClientConnection client, Message message)
        {
            await Task.Yield();

            await client.SendMessage(message);
        }