コード例 #1
0
 private void P2p_receiveServerEvent1(byte command, string text)
 {
     try
     {
         WeaveSession _0x01 = Newtonsoft.Json.JsonConvert.DeserializeObject <WeaveSession>(text);
         try
         {
             int         count  = listdtu.Count;
             dtuclient[] coobjs = new dtuclient[count];
             listdtu.CopyTo(0, coobjs, 0, count);
             foreach (dtuclient 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)
         {
             dtuclient dl      = new dtuclient();
             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);
         }
     }
 }