Beispiel #1
0
 void p2psev_EventDeleteConnSoc(System.Net.Sockets.Socket soc)
 {
     try
     {
         int       count  = ConnObjlist.Count;
         ConnObj[] coobjs = new ConnObj[count];
         ConnObjlist.CopyTo(0, coobjs, 0, count);
         foreach (ConnObj coob in coobjs)
         {
             if (coob != null)
             {
                 if (coob.Soc.Equals(soc))
                 {
                     ConnObjlist.Remove(coob);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         if (EventMylog != null)
         {
             EventMylog("加载异常", ex.Message);
         }
     }
 }
Beispiel #2
0
 public GateWay(bool IsWeb)
 {
     ConnObjlist = new ConnObj[max];
     if (IsWeb)
     {
         p2psev = new Webp2psever();
     }
     else
     {
         p2psev = new p2psever();
     }
 }
Beispiel #3
0
 public GateWay(bool IsWeb, int _max)
 {
     newwayEvent += GateWay_newwayEvent;
     max          = _max;
     ConnObjlist  = new ConnObj[max];
     if (IsWeb)
     {
         p2psev = new Webp2psever();
     }
     else
     {
         p2psev = new p2psever();
     }
 }
Beispiel #4
0
        //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);
                }
            }
        }
Beispiel #5
0
        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);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// 这里写接收到内容后,转发
        /// </summary>
        /// <param name="command"></param>
        /// <param name="text"></param>
        private void V_receiveServerEvent(byte command, string text)
        {
            _baseModel _0x01 = Newtonsoft.Json.JsonConvert.DeserializeObject <_baseModel>(text);

            try
            {
                int       count  = ConnObjlist.Count;
                ConnObj[] coobjs = new ConnObj[count];
                ConnObjlist.CopyTo(0, coobjs, 0, count);
                foreach (ConnObj coob in coobjs)
                {
                    if (coob != null)
                    {
                        if (coob.Token == _0x01.Token)
                        {
                            p2psev.WEBsend(coob.Soc, command, text);
                        }
                    }
                }
            }
            catch (Exception ex) { EventMylog("转发", ex.Message); }
        }
Beispiel #7
0
        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.WEBsend(soc, 0xff, cobj.Token))
                {
                    ConnObjlist.Add(cobj);
                }
            }
            catch (Exception ex)
            {
                if (EventMylog != null)
                {
                    EventMylog("EventUpdataConnSoc", ex.Message);
                }
            }
        }
Beispiel #8
0
        //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");
            int temp = 0;

            lock (tempnum)
            {
                if ((counttemp < max && tempnum.Count > 0) || (counttemp >= max && tempnum.Count > 0))
                {
                    temp = tempnum[0];
                    tempnum.RemoveAt(0);
                }
                else if (counttemp < max && tempnum.Count <= 0)
                {
                    temp = counttemp;
                    counttemp++;
                }
            }
            if (counttemp >= max && tempnum.Count == 0)
            {
                int    mincount = int.MaxValue;
                string tempip   = "";
                foreach (WayItem ci in WayItemS)
                {
                    if (ci.Num < mincount)
                    {
                        mincount = ci.Num;
                        tempip   = ci.Ip + ":" + ci.Port;
                    }
                }
                p2psev.send(soc, 0xff, "jump|" + tempip + "");

                soc.Close();
                return;
            }

            try
            {
                //IPEndPoint clientipe = (IPEndPoint)soc.RemoteEndPoint;
                cobj.Token = DateTime.Now.ToString("yyyyMMddHHmmssfff") + temp;// EncryptDES(clientipe.Address.ToString() + "|" + DateTime.Now.ToString(), "lllssscc");
                cobj.Id    = temp;
                if (p2psev.send(soc, 0xff, "token|" + cobj.Token + ""))
                {
                    ConnObjlist[temp] = cobj;
                }
                foreach (CommandItem ci in CommandItemS)
                {
                    if (ci.Client[ci.Client.Count - 1] != null)
                    {
                        ci.Client[ci.Client.Count - 1].send(0xff, "in|" + cobj.Token);
                    }
                }


                newwayEvent(temp);
            }
            catch (Exception ex)
            {
                if (EventMylog != null)
                {
                    EventMylog("EventUpdataConnSoc", ex.Message);
                }
            }
        }
Beispiel #9
0
        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, "您的请求是非法的~");
            //}
        }