Example #1
0
        public void BroadcastMessage(IChatMsg message)
        {
            if (string.IsNullOrEmpty(userName))
                throw new UnauthorizedAccessException("Please login first!");

            chatBroker.BroadcastMessage(userName, message);
        }
Example #2
0
        public void BroadcastMessage(string sourceUser, IChatMsg message)
        {
            Console.WriteLine($"New message from {sourceUser}: {message.Text}");

            for (int i = 0; i < clients.Count; i++)
            {
                try
                {
                    clients[i].OnNewMessage(sourceUser, message);
                }
                catch (OperationCanceledException)
                {
                    // connection close during send
                }
                catch (TimeoutException)
                {
                    // no response in time
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
        }
Example #3
0
 public void OnNewMessage(string sourceName, IChatMsg msg)
 {
     WriteColorLine(sourceName == username ? ConsoleColor.White : ConsoleColor.Green, $"{sourceName}:   {msg.Text}");
 }