예제 #1
0
파일: Peer.cs 프로젝트: shranjan/pinac
        public int InsertPeer(String ip, String port, String name, String cpu)
        {
            string ipport = ip + ":" + port;
            Peer nPeer = new Peer();
            nPeer.mIP = ip;
            nPeer.mPort = port;
            nPeer.mName = name;
            nPeer.mCPU = cpu;
            IPtoPeer[ipport] = nPeer;
            NametoIP[name] = ipport;

            if (ListChanged != null)
                ListChanged(IPtoPeer);

            return 1;
        }
예제 #2
0
        private void getChatMsg(String msg) 
        {
            try
            {
                string chat = "";
                string ip = "";
                XDocument xml = XDocument.Parse(msg);
                var q = from x in xml.Elements("root").Descendants()
                        select x;
                foreach (var elem in q)
                {

                    ip = elem.Attributes().ElementAt(0).Value;
                    chat = elem.Attributes().ElementAt(1).Value;
                }
                string name = "";
                Peer temp = new Peer();
                temp = (Peer)GetIPtoPeer()[ip];
                name = temp.mName;
                Console.WriteLine("{0}:{1}", name, chat);

                if (ChatChanged != null)
                    ChatChanged(name, chat);
            }
            catch (Exception e)
            { Console.WriteLine(e.ToString()); }
        }
예제 #3
0
파일: server.cs 프로젝트: rkpandya/pinac
 public void StarHeartBeat()
 {
     MessageGenerator temp=new MessageGenerator();
     string HeartBeatRequestmsg = temp.msgHeartBeatRequest(GetIP() + ":" + GetPort());
     while (true)
     {
         try
         {
             if (IPtoPeer.Count > 1)
             {
                 foreach (string IP in IPtoPeer.Keys)
                 {
                     if (IP != GetIP() + ":" + GetPort())
                     {
                         Peer p = new Peer();
                         p = (Peer)IPtoPeer[IP];
                         string ip = p.mIP;
                         string port = p.mPort;
                         HeartbeatClient client = new HeartbeatClient();
                         client.SetSingleMsg(ip, port, HeartBeatRequestmsg);
                         client.HeartBeatException += new HeartbeatClient.EventHandlerHeartBeat(ShutDown);
                         Thread t;
                         string sendtime = DateTime.Now.ToLongTimeString() + ":" + DateTime.Now.Millisecond.ToString();
                         InsertSendTime(ip+":"+port,sendtime);
                         t = new Thread(new ThreadStart(client.SendSingleClient));
                         t.IsBackground = true;
                         t.Start();
                         Thread.Sleep(3000);
                     }
                 }
             }
         }
         catch (Exception e)
         {
             Console.WriteLine(e.ToString());
         }
     }
 }
예제 #4
0
        //public void getReRun(ref Peer mPeer)
        //{
        //    string pid = " ";
        //    XDocument xml = XDocument.Parse(msg);
        //    var q = from x in xml.Descendants()
        //            where (x.Name == "root")
        //            select x;
        //    foreach (var elem in q)
        //        pid = elem.Value;
        //    mPeer.SetFlag(pid, "0");
        //}

        private void getChatMsg(String msg) 
        {
            string chat = "";
            string ip = "";
            XDocument xml = XDocument.Parse(msg);
            //var q = from x in xml.Descendants()
            //        where (x.Name == "root")
            //        select x;
            //foreach (var elem in q)
            //    chat = elem.Value;
            var q = from x in xml.Elements("root").Descendants()
                    select x;
            foreach (var elem in q)
            {

                ip = elem.Attributes().ElementAt(0).Value;
                chat = elem.Attributes().ElementAt(1).Value;
            }
            string name = "";
            Peer temp = new Peer();
            temp = (Peer)GetIPtoPeer()[ip];
            name = temp.mName;
            Console.WriteLine("{0}:{1}",name,chat);
            ////////////////////////////////////////////////
            if (ChatChanged != null)
                ChatChanged(name,chat);

            //
        }