Example #1
0
        private async Task BroadcastClientConnectedAsync(User user, IEnumerable <IClient> others)
        {
            var messageProtocol = new MessageProtocol
            {
                Header = MessageType.ClientConnectedOthers,
                Data   = user
            };

            var tcpClients = others.Select(i => i.TcpClient).ToArray();
            await MessageCommunicator.BroadcastAsync(tcpClients, messageProtocol);
        }
Example #2
0
        private async Task BroadcastClientDisconnectedAsync(User user)
        {
            if (user != null && _clientsPool.Remove(user.Id))
            {
                var messageProtocol = new MessageProtocol
                {
                    Header = MessageType.ClientDisconnected,
                    Data   = user
                };

                var tcpClients = _clientsPool.ConnectedClients.Select(i => i.Value.TcpClient).ToArray();
                if (tcpClients.Any())
                {
                    await MessageCommunicator.BroadcastAsync(tcpClients, messageProtocol);
                }
            }
        }
Example #3
0
        private async Task ForcelyDisconnectClient(IClient user)
        {
            if (user?.User != null && _clientsPool.Remove(user.User.Id))
            {
                var messageProtocol = new MessageProtocol
                {
                    Header = MessageType.ClientDisconnected,
                    Data   = user.User
                };

                var tcpClients = _clientsPool.ConnectedClients.Select(i => i.Value.TcpClient).ToArray();
                if (tcpClients.Any())
                {
                    await MessageCommunicator.BroadcastAsync(tcpClients, messageProtocol);
                }
            }

            Logger.Info($"Client disconnected abruptely. {user}");
        }