static void Main(string[] args)
        {
            string _ip;
            Console.Out.WriteLine("Server IP: ");
            _ip = Console.In.ReadLine();
            Client _client = new Client(_ip);

            string input = "";
            while (input != "quit")
            {
                Console.Out.Write(">");
                input = Console.In.ReadLine();
                _client.eManager._say(input);
            }
            _client.Close();
        }
 /// <summary>
 /// Sets next peer in the ring
 /// </summary>
 /// <param name="nextAddress">Address of the next peer to add</param>
 /// <returns>0 if no error occured</returns>
 public int setNext(string nextAddress)
 {
     if (nextAddress != "")
         next = new Client(nextAddress);
     else
         next = null;
     return 0;
 }
        private void register(string _input)
        {
            token.WaitOne();
            string[] _tokens = _input.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            if (_tokens.Count<string>() < 2)
            {
                Console.Out.WriteLine("Illegal arguments");
                Console.Out.WriteLine("register [ip]: Register the host with the given IP address as remote host.\r\n");
                return;
            }
            string _ip = _tokens[1];

            Client newClient = new Client(_ip);

            try
            {
                newClient.makeFunction("Say", new string[] { "Peer of address: " + getLocalIP() + ":8000/xmlrpc" + EventManager.servNum.ToString() + " registered you" });
            }
            catch
            {
                Console.Out.WriteLine("Wrong address given. Couldn't connect.");
                return;
            }

            if (EventManager.singleMachineDebug)
                //For debugging on a single machine
                newClient.makeFunction("AddNewPeer", new string[] { getLocalIP() + ":8000/xmlrpc" + EventManager.servNum.ToString() });
            else
                newClient.makeFunction("AddNewPeer", new string[] { getLocalIP() });
        }
 public int _register(string serverAddress)
 {
     Client newClient = new Client(serverAddress);
     Client.clientsMap.Add(serverAddress, newClient);
     return 0;
 }
 public int _drop(string ServerAddress)
 {
     if (next != null && next.address == ServerAddress)
         if (next.makeFunction("GetNext", null) == next.makeFunction("GetPrev", null))
         {
             next = null;
         }
         else
             next = new Client(Client.clientsMap[ServerAddress].makeFunction("GetNext", null));
     if (prev != null && prev.address == ServerAddress)
         if (prev.makeFunction("GetNext", null) == prev.makeFunction("GetPrev", null))
         {
             prev = null;
         }
         else
             prev = new Client(Client.clientsMap[ServerAddress].makeFunction("GetPrev", null));
     Client.clientsMap.Remove(ServerAddress);
     return 0;
 }
        public int _addNewPeer(string newPeerAddress)
        {
            waitsForToken = true;
            token.WaitOne();
            waitsForToken = false;

            Client newPeer = new Client(newPeerAddress);
            foreach (string address in Client.clientsMap.Keys)
            {
                newPeer.makeFunction("Register", new string[] { address });
                Client.clientsMap[address].makeFunction("Register", new string[] { newPeerAddress });
            }
            Client.clientsMap.Add(newPeerAddress, newPeer);
            if (EventManager.singleMachineDebug)
            {
                //For testing on a single machine
                newPeer.makeFunction("Register", new string[] { getLocalIP() + ":8000/xmlrpc" + EventManager.servNum.ToString() });
                newPeer.makeFunction("SetPrev", new string[] { getLocalIP() + ":8000/xmlrpc" + EventManager.servNum.ToString() });
            }
            else
            {
                newPeer.makeFunction("Register", new string[] { getLocalIP() });
                newPeer.makeFunction("SetPrev", new string[] { getLocalIP() });
            }

            if (next != null)
            {
                next.makeFunction("SetPrev", new string[] { newPeerAddress });
                newPeer.makeFunction("SetNext", new string[] { next.address });
            }
            else
            {
                if (EventManager.singleMachineDebug)
                    //For debugging on a single machine
                    newPeer.makeFunction("SetNext", new string[] { getLocalIP() + ":8000/xmlrpc" + EventManager.servNum.ToString() });
                else
                    newPeer.makeFunction("SetNext", new string[] { getLocalIP() });
                prev = newPeer;
            }
            next = newPeer;

            DirectoryInfo di = new DirectoryInfo(System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, "..\\..\\..\\events"));
            foreach (FileInfo fi in di.GetFiles())
            {
                StreamReader _sr = new StreamReader(File.Open(fi.FullName, FileMode.Open, FileAccess.Read));
                string _s = _sr.ReadLine();
                _sr.Close();
                string[] _tokens = _s.Split(new string[] { "\t" }, StringSplitOptions.RemoveEmptyEntries);
                newPeer.makeFunction("Add", _tokens);
            }

            forwardToken();
            return 0;
        }
 /// <summary>
 /// Sets previous peer in the ring
 /// </summary>
 /// <param name="prevAddress">Address of the previous peer to add</param>
 /// <returns>0 if no error occured</returns>
 public int setPrev(string prevAddress)
 {
     if (prevAddress != "")
         prev = new Client(prevAddress);
     else
         prev = null;
     return 0;
 }
 private void register(string _input)
 {
     string[] _tokens = _input.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
     if (_tokens.Count<string>() < 2)
     {
         Console.Out.WriteLine("Illegal arguments");
         Console.Out.WriteLine("register [ip]: Register the host with the given IP address as remote host.\r\n");
         return;
     }
     string _ip = _tokens[1];
     _register(_tokens[1]);
     Client newClient = new Client(_tokens[1]);
     newClient.eManager._register(getLocalIP());
 }