public void removeServer(HomeTransferServerData data)
 {
     if (homeTransferServerDictionary.ContainsKey(data.IP))
     {
         homeTransferServerDictionary.Remove(data.IP);
     }
 }
        private HomeTransferModel()
        {
            homeTransferServerDictionary = new Dictionary <String, HomeTransferServerData>();
            homeTransferFileDictionary   = new Dictionary <String, String>();

            String name = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
            String IP   = "";

            try
            {
                var host = Dns.GetHostEntry(Dns.GetHostName());
                foreach (var ip in host.AddressList)
                {
                    if (ip.AddressFamily == AddressFamily.InterNetwork)
                    {
                        IP = ip.ToString();
                        break;
                    }
                }
            } catch (Exception e)
            {
                Console.WriteLine("Error: Local host not available");
            }

            String port = "11" + IP.Substring(IP.Length - 2);

            port = port.Replace('.', '0');

            localData      = new HomeTransferServerData();
            localData.name = name;
            localData.IP   = IP;
            localData.port = Convert.ToInt32(port);
        }
 public void addServer(HomeTransferServerData data)
 {
     if (!(homeTransferServerDictionary.ContainsKey(data.IP) || data.IP.Equals(localData.IP)))
     {
         homeTransferServerDictionary.Add(data.IP, data);
         HomeTransferController.getInstance().updateObserver();
     }
 }
Example #4
0
        public static HomeTransferServerData createFromUDP(Byte[] packet)
        {
            HomeTransferServerData data = new HomeTransferServerData();
            String packetData           = System.Text.Encoding.Default.GetString(packet).Trim();

            String[] packetDataSplitted = packetData.Split(';');
            data.name = packetDataSplitted[0];
            data.IP   = packetDataSplitted[1];
            data.port = Convert.ToInt32(packetDataSplitted[2]);
            data.type = packetDataSplitted[3];
            return(data);
        }