Beispiel #1
0
 public void BroadcastMessage(MessageBase msg)
 {
     foreach(var key in clients.Keys)
     {
         clients[key].SendMessageAsync(msg);
     }
 }
Beispiel #2
0
        public void BroadcastLoggedIn()
        {
            MessageBase msg = new MessageBase();
            string users = null;
            msg.Type = (int)MessageBase.Types.LoggedInBroadcast;

            foreach (var key in clients.Keys)
            {
                users += clients[key].Nickname+",";
            }
            msg.LoggedInUsers = users;
            BroadcastMessage(msg);
        }
Beispiel #3
0
 private void OnMessageReceived(MessageBase msg)
 {
     Server.BroadcastMessage(msg);
 }
Beispiel #4
0
        /*
        * Serializes message to network stream.
        */
        public Task SendMessageAsync(MessageBase msg)
        {
            try
            {
                XmlSerializer x = new XmlSerializer(typeof (MessageBase));
                x.Serialize(Stream, msg);
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine("{0}", e);
            }
            catch (ArgumentException e)
            {
                Console.WriteLine("{0}", e);
            }

            return null;
        }