Esempio n. 1
0
        protected void ReloadFliesway(object obj)
        {
            try
            {
                foreach (WayItem ci in WayItemS)
                {
                    ci.Client.stop();
                }
                WayItemS.Clear();
                XmlDocument xml = new XmlDocument();
                xml.Load("nodeway.xml");
                foreach (XmlNode xn in xml.FirstChild.ChildNodes)
                {
                    WayItem ci = new WayItem();
                    ci.Ip     = xn.Attributes["ip"].Value;
                    ci.Port   = Convert.ToInt32(xn.Attributes["port"].Value);
                    ci.Token  = (xn.Attributes["token"].Value);
                    ci.Client = new P2Pclient(false);
                    ci.Client.receiveServerEvent += Client_receiveServerEvent;
                    ci.Client.timeoutevent       += Client_timeoutevent;
                    ci.Client.ErrorMge           += Client_ErrorMge;
                    if (ci.Client.start(ci.Ip, ci.Port, false))
                    {
                        _baseModel oxff = new _baseModel();
                        oxff.Request = "token";
                        oxff.Root    = ci.Token;
                        ci.Client.send(0xff, oxff.Getjson());
                        WayItemS.Add(ci);
                    }
                    else
                    {
                        if (EventMylog != null)
                        {
                            EventMylog("从网关连接失败", "从网关:" + ci.Ip + ":节点连接失败,抛弃此节点");
                        }
                    }
                }

                System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(getwaynum));
            }
            catch (Exception ex)
            {
                if (EventMylog != null)
                {
                    EventMylog("加载异常", ex.Message);
                }
            }
        }
Esempio n. 2
0
 public void getwaynum(object obj)
 {
     while (true)
     {
         try
         {
             int       count  = WayItemS.Count;
             WayItem[] coobjs = new WayItem[count];
             WayItemS.CopyTo(0, coobjs, 0, count);
             foreach (WayItem wi in coobjs)
             {
                 _baseModel oxff = new _baseModel();
                 oxff.Request = "getnum";
                 oxff.Root    = wi.Token;
                 wi.Client.send(0xff, oxff.Getjson());
             }
         }
         catch { }
         System.Threading.Thread.Sleep(2000);
     }
 }
Esempio n. 3
0
        protected void Client_receiveServerEvent(byte command, string text)
        {
            try
            {
                _baseModel _0x01 = Newtonsoft.Json.JsonConvert.DeserializeObject <_baseModel>(text);

                if (_0x01.Request == "setnum")
                {
                    int       count  = WayItemS.Count;
                    WayItem[] coobjs = new WayItem[count];
                    WayItemS.CopyTo(0, coobjs, 0, count);
                    foreach (WayItem wi in coobjs)
                    {
                        if (wi.Token == _0x01.Token)
                        {
                            wi.Num = int.Parse(_0x01.Root);
                        }
                    }
                }
            }
            catch { }
        }