Пример #1
0
        public void BroadcastMessageAsync(IMessage message)
        {
            for (int i = 0; i < mGroupClients.Count; ++i)
            {
                IClientDetails currClientDetails = mGroupClients[i];
                IClient        currClient        = null;

                if (clientConnections.ContainsKey(currClientDetails))
                {
                    currClient = clientConnections[currClientDetails];
                }
                else
                {
                    currClient = new P2PClient(ListenPort, currClientDetails.ClientIPAddress,
                                               currClientDetails.ClientListenPort, Group);
                    currClient.Initialize();
                }

                currClient.SendMessageAsync(message);

                if (!clientConnections.ContainsKey(currClientDetails))
                {
                    clientConnections[currClientDetails] = currClient;
                }
            }
        }
Пример #2
0
        public void SendMessageAsync(IMessage message, IClientDetails details)
        {
            if (message == null)
            {
                //throw a null reference exception
                throw new NullReferenceException("The supplied IMessage object is null!");
            }

            if (details == null)
            {
                //throw a null reference exception
                throw new NullReferenceException("The supplied IClientDetails object is null!");
            }

            IClient currClient = null;

            if (clientConnections.ContainsKey(details))
            {
                currClient = clientConnections[details];
            }
            else
            {
                currClient = new P2PClient(ListenPort, details.ClientIPAddress, details.ClientListenPort, Group);
                currClient.Initialize();
            }

            currClient.SendMessageAsync(message);

            if (!clientConnections.ContainsKey(details))
            {
                clientConnections[details] = currClient;
            }
        }
Пример #3
0
 public int CompareTo(IClientDetails other)
 {
     if (Equals(other))
     {
         return(0);
     }
     else
     {
         return(1);
     }
 }
Пример #4
0
        public void BroadcastMessageAsyncExceptAddress(string[] addressesToExclude, IMessage message)
        {
            for (int i = 0; i < mGroupClients.Count; ++i)
            {
                IClientDetails currClientDetails = mGroupClients[i];

                var skip = false;
                for (var j = 0; j < addressesToExclude.Length; j++)
                {
                    if (addressesToExclude[j] == currClientDetails.ToString())
                    {
                        skip = true;
                    }
                }
                if (skip)
                {
                    continue;       //skip if should be excluded
                }
                //set client
                IClient currClient = null;
                if (clientConnections.ContainsKey(currClientDetails))
                {
                    currClient = clientConnections[currClientDetails];
                }
                else
                {
                    currClient = new P2PClient(ListenPort, currClientDetails.ClientIPAddress, currClientDetails.ClientListenPort, Group);
                    currClient.Initialize();
                }
                //send message
                currClient.SendMessageAsync(message);

                //add to clientConnections if not there already
                if (!clientConnections.ContainsKey(currClientDetails))
                {
                    clientConnections[currClientDetails] = currClient;
                }
            }
        }
Пример #5
0
        public void SendMessageToAddressAsync(IMessage message, string address)
        {
            if (address == null)
            {
                //throw a null reference exception
                throw new NullReferenceException("The supplied address is null!");
            }

            if (address.Length == 0)
            {
                //throw an exception
                throw new Exception("The supplied address is invalid!");
            }

            IClientDetails details = null;

            if (this.GroupClients == null)
            {
                throw new NullReferenceException("The clients list is null!");
            }

            if (this.GroupClients.Count == 0)
            {
                throw new Exception("There are no clients available!");
            }

            for (int i = 0; i < GroupClients.Count; ++i)
            {
                if (GroupClients[i].ClientIPAddress + ":" + GroupClients[i].ClientListenPort == address)
                {
                    details = GroupClients[i];
                    break;
                }
            }

            SendMessageAsync(message, details);
        }
Пример #6
0
 public ServerRegisterEventArgs(IClientDetails newClient)
 {
     mNewClient = newClient;
 }