P2Pclient newp2p(String Ip, int Port) { P2Pclient p2p = new P2Pclient(false); p2p.ReceivesSpeedMode = WeaveReceivesSpeedMode.middle; if (Wptype == WeavePortTypeEnum.Bytes) { p2p.ReceiveServerEventbit += P2p_receiveServerEventbit; } else { p2p.ReceiveServerEvent += (V_receiveServerEvent); } p2p.Timeoutobjevent += P2p_timeoutobjevent; p2p.ErrorMge += (V_ErrorMge); if (p2p.Start(Ip, Port, false)) { return(p2p); } else { if (EventMylog != null) { EventMylog("节点连接失败", "命令:" + Ip + ":" + Port + ":节点连接失败,抛弃此节点"); } } return(null); }
public override bool getdata(HttpProcessor p, byte command, string data) { string returnstr = ""; foreach (CommandItem ci in CommandItems) { if (ci.CommName == command) { P2Pclient p2p = new P2Pclient(false); p2p.ReceiveServerEvent += new P2Pclient.receive((c, text) => { returnstr = text; }); //p2p.timeoutevent += (V_timeoutevent); p2p.ErrorMge += (V_ErrorMge); if (p2p.Start(ci.Ip, ci.Port, false)) { System.Threading.Thread.Sleep(200); p2p.Send(command, data); int count = 0; while (returnstr == "") { System.Threading.Thread.Sleep(200); if (count > 450) { p.outputStream.WriteLine("响应超时"); return(false); } count++; } p.outputStream.WriteLine(returnstr); return(true); } else { p.outputStream.WriteLine("不能连接指定的服务"); return(false); } } // _0x01. } p.outputStream.WriteLine("不能找到指定的服务"); int i = httpProcessorList.Count; HttpProcessor[] hps = new HttpProcessor[i]; httpProcessorList.CopyTo(hps); foreach (HttpProcessor hp in hps) { if (hp == p) { httpProcessorList.Remove(p); return(true); } } return(false); }
//int i = 0; void tt() { // timer1.Start(); for (int i = 0; i < 300; i++) { P2Pclient p2pc = new P2Pclient(DataType.custom); p2pc.ReceiveServerEvent += P2pc_receiveServerEvent; //接收数据事件 p2pc.ReceiveServerEventbit += P2pc_receiveServerEventbit; p2pc.Timeoutevent += P2pc_timeoutevent; //超时(掉线)事件 p2pc.Start("127.0.0.1", 8989, false); //11002 是网关的端口号,刚才WEB网关占用了11001,我改成11002了 p2pc.Send(new byte[1000]); //p2pc.SendRoot<int>(0x01, "login", 99987, 0); System.Threading.Thread.Sleep(5); } }
private void button1_Click_1(object sender, EventArgs e) { p2pc = new P2Pclient(false); p2pc.AddListenClass(this); p2pc.ReceiveServerEvent += P2pc_receiveServerEvent; //接收数据事件 p2pc.Timeoutevent += P2pc_timeoutevent; //超时(掉线)事件 p2pc.Start("127.0.0.1", 8989, true); //11002 是网关的端口号,刚才WEB网关占用了11001,我改成11002了 ; p2pc.SendRoot <String>(0x04, "login", "", 0); System.Threading.Thread.Sleep(5); // p2pc.Tokan = "123"; // p2pc.SendRoot<String>(0x01, "login", "999899987999879998799987999879998799987999879999989998799987999879998799987999879998799987999879998799987999879998799987999879998799987999879998799987999879998799987798799987999879999899987999879998799987999879998799987999879999989998799987999879998799987999879998799987999879998799987999879998799987999879998799987999879998799987999879998799987798799987999879998799987999879998799987999879998799987999879998799987999877999899987999879998799987999879998799987999879999989998799987999879998799987999879998799987999879998799987999879998799987999879998799987999879998799987999879998799987798799987999879998799987999879998799987999879998799987999879998799987999877998799987999879998799987999879998799987999879998799987999877", 0); //// p2pc.SendRoot<int>(0x01, "login", 34534534, 0); // System.Threading.Thread.Sleep(5); }
static void Main(string[] args) { modbus mod = new modbus(); mod.name = "aaa";//这里可以是设备的ID号; mod.ip = "116.255.252.181"; mod.port = 9903; modlist.Add(mod); foreach (modbus m in modlist) { P2Pclient client = new P2Pclient(DataType.bytes); client.ReceiveServerEventbitobj += Client_receiveServerEventbitobj; client.ReceiveServerEventobj += Client_ReceiveServerEventobj; client.Timeoutobjevent += Client_timeoutobjevent; if (client.Start(m.ip, m.port, false)) { m.client = client; } } System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(gogo)); t.Start(); }
protected void ReloadFlies2(object obj) { try { foreach (CommandItem ci in CommandItemS2) { foreach (P2Pclient Client in ci.Client) { Client.Stop(); } } CommandItemS2.Clear(); foreach (CommandItem ci in CommandItemS) { foreach (P2Pclient Client in ci.Client) { Client.Stop(); } } CommandItemS.Clear(); XmlDocument xml = new XmlDocument(); xml.Load(System.AppDomain.CurrentDomain.BaseDirectory + "/" + filename); foreach (XmlNode xn in xml.FirstChild.ChildNodes) { CommandItem ci = new CommandItem(); ci.Ip = xn.Attributes["ip"].Value; ci.Port = Convert.ToInt32(xn.Attributes["port"].Value); ci.CommName = byte.Parse(xn.Attributes["command"].Value); ci.Commfun = xn.Attributes["Commfun"].Value; P2Pclient p2p = new P2Pclient(false); p2p.ReceiveServerEvent += P2p_receiveServerEvent; p2p.Timeoutevent += P2p_timeoutevent; p2p.ErrorMge += P2p_ErrorMge; if (p2p.Start(ci.Ip, ci.Port, false)) { ci.Client.Add(p2p); if (xn.Attributes["type"].Value == "receive") { CommandItemS.Add(ci); } else if (xn.Attributes["type"].Value == "push") { CommandItemS2.Add(ci); } } else { if (EventMylog != null) { EventMylog("节点连接失败", "命令:" + ci.CommName + ":节点连接失败,抛弃此节点"); } } } } catch (Exception ex) { if (EventMylog != null) { EventMylog("加载异常", ex.Message); } } }