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.timeoutobjevent += Client_timeoutobjevent; ci.Client.ErrorMge += Client_ErrorMge; if (ci.Client.start(ci.Ip, ci.Port, false)) { WeaveSession oxff = new WeaveSession(); 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); } } }
protected void Client_receiveServerEvent(byte command, string text) { try { WeaveSession _0x01 = Newtonsoft.Json.JsonConvert.DeserializeObject <WeaveSession>(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 { } }
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) { WeaveSession oxff = new WeaveSession(); oxff.Request = "getnum"; oxff.Root = wi.Token; wi.Client.send(0xff, oxff.Getjson()); } } catch { } System.Threading.Thread.Sleep(2000); } }