//ThreadSafeDictionary<string, ConnObj> ConnObjlist = new ThreadSafeDictionary<string, ConnObj>(); protected void p2psev_EventUpdataConnSoc(System.Net.Sockets.Socket soc) { ConnObj cobj = new ConnObj(); cobj.Soc = soc; IPEndPoint clientipe = (IPEndPoint)soc.RemoteEndPoint; cobj.Token = EncryptDES(clientipe.Address.ToString() + "|" + DateTime.Now.ToString(), "lllssscc"); try { if (p2psev.send(soc, 0xff, "token|" + cobj.Token + "")) { ConnObjlist.Add(cobj); } int len = ConnObjlist.Count / Proportion; foreach (CommandItem ci in CommandItemS) { if (len > ci.Client.Count) { P2Pclient p2p = new P2Pclient(false); p2p.receiveServerEvent += V_receiveServerEvent; p2p.timeoutevent += V_timeoutevent; p2p.ErrorMge += V_ErrorMge; if (p2p.start(ci.Ip, ci.Port, false)) { ci.Client.Add(p2p); } } } int count = CommandItemS.Count; CommandItem[] comItems = new CommandItem[count]; CommandItemS.CopyTo(0, comItems, 0, count); foreach (CommandItem ci in comItems) { ci.Client[0].send(0xff, "in|" + cobj.Token); } } catch (Exception ex) { if (EventMylog != null) { EventMylog("EventUpdataConnSoc", ex.Message); } } }
protected void ReloadFlies(object obj) { try { foreach (CommandItem ci in CommandItemS) { foreach (P2Pclient Client in ci.Client) { Client.stop(); } } CommandItemS.Clear(); XmlDocument xml = new XmlDocument(); xml.Load("node.xml"); 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); P2Pclient p2p = new P2Pclient(false); p2p.receiveServerEvent += (V_receiveServerEvent); p2p.timeoutevent += (V_timeoutevent); p2p.ErrorMge += (V_ErrorMge); if (p2p.start(ci.Ip, ci.Port, false)) { ci.Client.Add(p2p); CommandItemS.Add(ci); } else { if (EventMylog != null) { EventMylog("节点连接失败", "命令:" + ci.CommName + ":节点连接失败,抛弃此节点"); } } } } catch (Exception ex) { if (EventMylog != null) { EventMylog("加载异常", ex.Message); } } }
protected void p2psev_EventDeleteConnSoc(System.Net.Sockets.Socket soc) { try { ConnObj[] coobjs = new ConnObj[0]; int count = 0; try { count = ConnObjlist.Count; coobjs = new ConnObj[count]; ConnObjlist.CopyTo(coobjs); } catch { } //ThreadList<ConnObj> coobjs = ConnObjlist.Clone(); foreach (ConnObj coob in coobjs) { if (coob != null) { if (coob.Soc.Equals(soc)) { ConnObjlist.Remove(coob); try { count = CommandItemS.Count; CommandItem[] comItems = new CommandItem[count]; CommandItemS.CopyTo(0, comItems, 0, count); foreach (CommandItem ci in comItems) { ci.Client[0].send(0xff, "out|" + coob.Token); } } catch { } } } } } catch (Exception ex) { if (EventMylog != null) { EventMylog("加载异常", ex.Message); } } }
public void ReloadFlies() { try { listcomm = new List <CommandItem>(); String[] strfilelist = System.IO.Directory.GetFiles(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "command"); foreach (string file in strfilelist) { Assembly ab = Assembly.LoadFile(file); Type[] types = ab.GetExportedTypes(); foreach (Type t in types) { try { if (t.IsSubclassOf(typeof(TCPCommand))) { CommandItem ci = new CommandItem(); object obj = ab.CreateInstance(t.FullName); TCPCommand Ic = obj as TCPCommand; ci.MyICommand = Ic; ci.CommName = Ic.Getcommand(); Ic.SetGlobalQueueTable(qt); GetAttributeInfo(Ic, obj.GetType(), obj); listcomm.Add(ci); } } catch { } } } } catch (Exception ex) { if (EventMylog != null) { EventMylog("加载异常", ex.Message); } } }
void p2psev_EventUpdataConnSoc(System.Net.Sockets.Socket soc) { try { int count = listcomm.Count; CommandItem[] cilist = new CommandItem[count]; listcomm.CopyTo(0, cilist, 0, count); foreach (CommandItem CI in cilist) { try { CI.MyICommand.TCPCommand_EventUpdataConnSoc(soc); } catch (Exception ex) { if (EventMylog != null) { EventMylog("EventUpdataConnSoc", ex.Message); } } } } catch { } }
protected void p2psev_receiveevent(byte command, string data, System.Net.Sockets.Socket soc) { _baseModel _0x01 = Newtonsoft.Json.JsonConvert.DeserializeObject <_baseModel>(data); if (_0x01.Token == null) { return; } string key = ""; string ip = ""; //try //{ // key = DecryptDES(_0x01.Token, "lllssscc"); // ip = key.Split('|')[0]; //} //catch { return; } IPEndPoint clientipe = (IPEndPoint)soc.RemoteEndPoint; //if (clientipe.Address.ToString() == ip) //{ int count = CommandItemS.Count; int counts = ConnObjlist.Count; ConnObj[] coobjs = new ConnObj[counts]; ConnObjlist.CopyTo(coobjs); CommandItem[] comItems = new CommandItem[count]; CommandItemS.CopyTo(0, comItems, 0, count); foreach (CommandItem ci in comItems) { if (ci != null) { if (ci.CommName == command) { int i = 0; for (int s = 0; s < counts; s++) { if (coobjs[s] != null) { if (coobjs[s].Token == _0x01.Token) { i = s; } } } int len = i / Proportion; if (!ci.Client[len >= ci.Client.Count? ci.Client.Count - 1: len].send(command, data)) { p2psev.send(soc, 0xff, "你所请求的服务暂不能使用,请联系管理人员。"); } return; } } } p2psev.send(soc, 0xff, "你所请求的服务是不存在的。"); // } //else //{ // p2psev.send(soc, 0xff, "您的请求是非法的~"); //} }