//Broadcast the message to the recipients

        public void Broadcast(byte[] packet, Chat.Clients recipients)
        {
            //If the dataset is Nothing, broadcast to everyone
            if (recipients == null)
            {
                foreach (DictionaryEntry c in IPList)
                {
                    //Broadcast the message to all users
                    ((Server)c.Value).SendMessage(packet);
                }
            }
            else
            {
                //Broadcast to selected recipients
                foreach (DictionaryEntry c in IPList)
                {
                    foreach (Chat.Client usr in recipients.List)
                    {
                        if (((Server)c.Value).ClientName == usr.Name)
                        {
                            //Send message to the recipient
                            ((Server)c.Value).SendMessage(packet);

                            //---log it locally
                            //Console.WriteLine("sending -----> " & message)
                            break; // TODO: might not be correct. Was : Exit For
                        }
                    }
                }
            }
        }
        internal void receivedData(Chat.Packet packet)
        {
            Chat.Clients recipients = new Chat.Clients();

            if (packet != null)
            {
                switch (packet.ID)
                {
                case Chat.Action.Join:

                    // Deserialize the content
                    Chat.Client usr = Chat.Client.Deserialize(packet.Content);
                    ClientName = usr.Name;

                    // Add the user set to receive a full list of user
                    recipients.List.Add(usr);

                    Chat.Clients usrs = new Chat.Clients();
                    foreach (DictionaryEntry c in IPList)
                    {
                        Chat.Client u = new Chat.Client();
                        u.Name = ((Server)c.Value).ClientName;
                        usrs.List.Add(u);
                    }

                    byte[] msg = Chat.Serialize(Chat.Action.ClientList, usrs);

                    //Send the full user list to the user that just signed on
                    Broadcast(msg, recipients);

                    //Rebroadcast the original message to everyone that this user is online
                    Broadcast(Data, null);

                    break;

                case Chat.Action.Message:
                    Chat.Message message = Chat.Message.Deserialize(packet.Content);

                    foreach (Chat.Client recipient in message.Reciptients)
                    {
                        recipients.List.Add(recipient);
                    }

                    //Send the message to the recipients
                    Broadcast(Data, recipients);
                    break;

                default:

                    break;
                }
            }
        }
        //Delegate and subroutine to update the textBox control
        //Friend Delegate Sub delUpdateHistory(ByVal str As String)
        internal void receivedData(Chat.Packet packet)
        {
            switch (packet.ID)
            {
            case Chat.Action.Join:

                Chat.Client usr = Chat.Client.Deserialize(packet.Content);
                lstUsers.Items.Add(usr.Name);

                break;

            case Chat.Action.ClientList:
                lstUsers.Items.Clear();

                Chat.Clients usrs = Chat.Clients.Deserialize(packet.Content);
                foreach (Chat.Client u in usrs.List)
                {
                    if (Client.Name != u.Name)
                    {
                        lstUsers.Items.Add(u.Name);
                    }
                }

                break;

            case Chat.Action.Message:
                //Read the message
                Chat.Message msg = Chat.Message.Deserialize(packet.Content);

                switch (msg.Type)
                {
                case Chat.MGSType.Chat:

                    break;

                case Chat.MGSType.PowerShell:

                    break;

                case Chat.MGSType.ComputerInfo:

                    break;
                }

                //Read the recipients...

                //Update the recipient's message history
                txtMessageHistory.Text += msg.Sender.Name + " - " + msg.MSG + Environment.NewLine;
                break;

            case Chat.Action.Disconnect:
                Chat.Client user = Chat.Client.Deserialize(packet.Content);

                //Remove the user from the listbox
                lstUsers.Items.Remove(user.Name);

                break;

            default:
                break;
            }
        }