示例#1
0
 private void P2p_receiveServerEvent1(byte command, string text)
 {
     try
     {
         WeaveSession _0x01 = Newtonsoft.Json.JsonConvert.DeserializeObject <WeaveSession>(text);
         try
         {
             int count = listdtu.Count;
             Dtuclientcloud[] coobjs = new Dtuclientcloud[count];
             listdtu.CopyTo(0, coobjs, 0, count);
             foreach (Dtuclientcloud coob in coobjs)
             {
                 if (coob != null)
                 {
                     if (coob.Token == _0x01.Token)
                     {
                         coob.Tcpdtu.Send(_0x01.GetRoot <byte[]>());
                         return;
                     }
                 }
             }
         }
         catch (Exception ex) { EventMylog("转发", ex.Message); }
     }
     catch { }
 }
示例#2
0
 protected void ReloadFliesdtu(object obj)
 {
     try
     {
         XmlDocument xml = new XmlDocument();
         xml.Load("dtulist.xml");
         foreach (XmlNode xn in xml.FirstChild.ChildNodes)
         {
             Dtuclientcloud dl      = new Dtuclientcloud();
             String         ip      = xn.Attributes["ip"].Value;
             int            Port    = Convert.ToInt32(xn.Attributes["port"].Value);
             string         Commfun = xn.Attributes["Commfun"].Value;
             DTUclient      p2p     = new DTUclient();
             p2p.ReceiveServerEvent += P2p_receiveServerEvent3;;
             p2p.Timeoutevent       += P2p_timeoutevent1;
             p2p.ErrorMge           += P2p_ErrorMge;
             if (p2p.Start(ip, Port, false))
             {
                 dl.Tcpdtu = p2p;
                 dl.Token  = ip + "|" + Port;
                 p2p.Tokan = ip + "|" + Port;
                 listdtu.Add(dl);
                 foreach (CommandItem ci in CommandItemS2)
                 {
                     if (Commfun == ci.Commfun)
                     {
                         foreach (P2Pclient Client in ci.Client)
                         {
                             Client.Tokan = dl.Token;
                             Client.SendRoot <byte[]>(ci.CommName, ci.Commfun, new byte[0], 0);
                         }
                     }
                 }
             }
             else
             {
                 if (EventMylog != null)
                 {
                     EventMylog("DTU客户端连接失败", "DTU客户端:" + ip + "|" + Port + "连接失败。");
                 }
             }
         }
     }
     catch (Exception ex)
     {
         if (EventMylog != null)
         {
             EventMylog("加载异常", ex.Message);
         }
     }
 }