Exemplo n.º 1
0
        public ConnObj getconn(String ip, int port)
        {
            ConnObj[] cobs = new ConnObj[Connlist.Count];
            Connlist.CopyTo(0, cobs, 0, cobs.Length);

            foreach (ConnObj cb in cobs)
            {
                if (cb != null)
                {
                    try
                    {
                        if (cb.Soc.RemoteEndPoint != null)
                        {
                            IPEndPoint clientipe = (IPEndPoint)cb.Soc.RemoteEndPoint;
                            if ((clientipe.Address.ToString() + ":" + clientipe.Port) == (ip + ":" + port))
                            {
                                return(cb);
                            }
                        }
                    }
                    catch { }
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        private void P2p_receiveServerEventbit(byte command, byte[] data)
        {
            try {
                if (data.Length < 6)
                {
                    return;
                }
                byte[] b = new byte[6];
                data.CopyTo(b, data.Length - b.Length);
                ConnObj cobj = GateHelper.GetConnItemlistByindex(ConnItemlist, b, Pipeline);
                if (cobj != null)
                {
                    int error = 0;
lb1122:
                    if (!p2psev.Send(cobj.Soc, command, data))
                    {
                        error += 1;
                        EventMylog("转发" + error, "ConnObjlist:发送失败:byte");
                        if (error < 3)
                        {
                            goto lb1122;
                        }
                    }
                }
                else
                {
                    EventMylog("转发", "ConnObjlist:byte是空的");
                }
                return;
            } catch { }
        }
Exemplo n.º 3
0
        public void removeconn(Socket soc)
        {
            ConnObj[] cobs = new ConnObj[Connlist.Count];
            Connlist.CopyTo(0, cobs, 0, cobs.Length);

            for (int i = 0; i < count; i++)
            {
                if (cobs[i] != null)
                {
                    if (cobs[i].Soc.Equals(soc))
                    {
                        try
                        {
                            cobs[i].Soc.Dispose();
                        }
                        catch { }
                        try
                        {
                            Connlist.Remove(cobs[i]);
                        }
                        catch { }
                        return;
                    }
                }
            }
        }
Exemplo n.º 4
0
 private void P2p_receiveServerEvent(byte command, string text)
 {
     try
     {
         WeaveSession _0x01 = Newtonsoft.Json.JsonConvert.DeserializeObject <WeaveSession>(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)
                     {
                         coob.Soc.Send(_0x01.GetRoot <byte[]>());
                         return;
                     }
                 }
             }
         }
         catch (Exception ex) { EventMylog("转发", ex.Message); }
     }
     catch { }
 }
Exemplo n.º 5
0
        /// <summary>
        /// 将对象存入数组对象中
        /// </summary>
        /// <param name="ConnItemlist"></param>
        /// <param name="connb"></param>
        /// <param name="pipeline"></param>
        public static void SetConnItemlist(clientItem[,,,] ConnItemlist, ConnObj connb, WeavePipelineTypeEnum pipeline)
        {
            IPEndPoint clientipe = (IPEndPoint)connb.Soc.RemoteEndPoint;

            if (pipeline == WeavePipelineTypeEnum.ten)
            {
                string t = clientipe.Port.ToString().Substring(clientipe.Port.ToString().Length - 1);
                connb.Id = Convert.ToInt32(t);
                if (ConnItemlist[0, 0, 0, Convert.ToInt32(t)] == null)
                {
                    ConnItemlist[0, 0, 0, Convert.ToInt32(t)] = new clientItem();
                }
                ConnItemlist[0, 0, 0, Convert.ToInt32(t)].setconn(connb);
            }
            else if (pipeline == WeavePipelineTypeEnum.hundred)
            {
                string t = clientipe.Port.ToString().Substring(clientipe.Port.ToString().Length - 2);
                connb.Id = Convert.ToInt32(t);
                if (ConnItemlist[0, 0, Convert.ToInt32(t.Substring(0, 1)), Convert.ToInt32(t.Substring(1, 1))] == null)
                {
                    ConnItemlist[0, 0, Convert.ToInt32(t.Substring(0, 1)), Convert.ToInt32(t.Substring(1, 1))] = new clientItem();
                }
                ConnItemlist[0, 0, Convert.ToInt32(t.Substring(0, 1)), Convert.ToInt32(t.Substring(1, 1))].setconn(connb);
            }
            else if (pipeline == WeavePipelineTypeEnum.thousand)
            {
                string t = clientipe.Port.ToString().Substring(clientipe.Port.ToString().Length - 2);
                string m = clientipe.Address.ToString().Substring(clientipe.Address.ToString().Length - 1);
                connb.Id = Convert.ToInt32(m + t);
                if (ConnItemlist[0, Convert.ToInt32(m), Convert.ToInt32(t.Substring(0, 1)), Convert.ToInt32(t.Substring(1, 1))] == null)
                {
                    ConnItemlist[0, Convert.ToInt32(m), Convert.ToInt32(t.Substring(0, 1)), Convert.ToInt32(t.Substring(1, 1))] = new clientItem();
                }
                ConnItemlist[0, Convert.ToInt32(m), Convert.ToInt32(t.Substring(0, 1)), Convert.ToInt32(t.Substring(1, 1))].setconn(connb);
            }
            else if (pipeline == WeavePipelineTypeEnum.ten_thousand)
            {
                string t = clientipe.Port.ToString().Substring(clientipe.Port.ToString().Length - 2);
                string m = clientipe.Address.ToString().Split('.')[3];

                if (m.Length < 2)
                {
                    m = "0" + m;
                }
                connb.Id = Convert.ToInt32(m + t);
                if (ConnItemlist[Convert.ToInt32(m.Substring(0, 1)), Convert.ToInt32(m.Substring(1, 1)), Convert.ToInt32(t.Substring(0, 1)), Convert.ToInt32(t.Substring(1, 1))] == null)
                {
                    ConnItemlist[Convert.ToInt32(m.Substring(0, 1)), Convert.ToInt32(m.Substring(1, 1)), Convert.ToInt32(t.Substring(0, 1)), Convert.ToInt32(t.Substring(1, 1))] = new clientItem();
                }
                ConnItemlist[Convert.ToInt32(m.Substring(0, 1)), Convert.ToInt32(m.Substring(1, 1)), Convert.ToInt32(t.Substring(0, 1)), Convert.ToInt32(t.Substring(1, 1))].setconn(connb);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 这里写接收到服务器发送的消息转发给客户端
        /// </summary>
        /// <param name="command"></param>
        /// <param name="text"></param>
        protected void V_receiveServerEvent(byte command, string text)
        {
            try
            {
                if (text == "")
                {
                    return;
                }
                WeaveSession _0x01 = null;
                try
                {
                    _0x01 = Newtonsoft.Json.JsonConvert.DeserializeObject <WeaveSession>(text);
                }
                catch { return; }
                int    temp = 0;
                String ip   = "";
                int    port = 0;
                try
                {
                    ip               = _0x01.Token.Split(':')[0];
                    port             = Convert.ToInt32(_0x01.Token.Split(':')[1]);
                    _0x01.Querycount = temp;
                }
                catch
                {
                    EventMylog("转发", "获取编号失败。" + _0x01.Token);
                    return;
                }
                ConnObj cobj = GateHelper.GetConnItemlist(ConnItemlist, ip, port, Pipeline);
                if (cobj != null)
                {
                    int error = 0;
lb1122:
                    if (!p2psev.Send(cobj.Soc, command, text))
                    {
                        error += 1;
                        EventMylog("转发" + error, "ConnObjlist:发送失败:" + text);
                        if (error < 3)
                        {
                            goto lb1122;
                        }
                    }
                }
                else
                {
                    EventMylog("转发", "ConnObjlist:" + temp + "是空的");
                }
                return;
            }
            catch (Exception ex) { EventMylog("转发", ex.Message + "112223333333333356464122313" + text + "000000"); }
        }
Exemplo n.º 7
0
        private void DTUSer_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
            {
                IPEndPoint clientipe = (IPEndPoint)soc.RemoteEndPoint;
                cobj.Token = clientipe.Address.ToString() + "|" + clientipe.Port;// EncryptDES(clientipe.Address.ToString() + "|" + DateTime.Now.ToString(), "lllssscc");
                ConnObjlist.Add(cobj);
            }
            catch { }
        }
Exemplo n.º 8
0
 public ConnObj getconn(Socket soc)
 {
     ConnObj[] cobs = new ConnObj[Connlist.Count];
     Connlist.CopyTo(0, cobs, 0, cobs.Length);
     foreach (ConnObj cb in cobs)
     {
         try
         {
             if (cb != null)
             {
                 if (cb.Soc.Equals(soc))
                 {
                     return(cb);
                 }
             }
         }
         catch { }
     }
     return(null);
 }
Exemplo n.º 9
0
        private void DTUSer_EventDeleteConnSoc(System.Net.Sockets.Socket soc)
        {
            ConnObj[] coobjs = new ConnObj[0];
            int       count  = 0;

            try
            {
                count  = ConnObjlist.Count;
                coobjs = new ConnObj[count];
                ConnObjlist.CopyTo(coobjs);
            }
            catch { }
            foreach (ConnObj coob in coobjs)
            {
                if (coob != null)
                {
                    if (coob.Soc.Equals(soc))
                    {
                        ConnObjlist.Remove(coob);
                    }
                }
            }
        }
Exemplo n.º 10
0
 public void setconn(ConnObj cb)
 {
     _Connlist.Add(cb);
 }
Exemplo n.º 11
0
        protected void p2psev_EventUpdataConnSoc(System.Net.Sockets.Socket soc)
        {
            ConnObj cobj = new ConnObj();

            try {
                cobj.Soc = soc;
                IPEndPoint clientipe = (IPEndPoint)soc.RemoteEndPoint;


                counttemp++;
                //这里通过IP和PORT获取对象

                cobj.Token = clientipe.Address.ToString() + ":" + clientipe.Port;// EncryptDES(clientipe.Address.ToString() + "|" + DateTime.Now.ToString(), "lllssscc");

                cobj.Soc = soc;


                if (counttemp > max)
                {
                    int    mincount = int.MaxValue;
                    string tempip   = "";
                    foreach (WayItem ci in WayItemS)
                    {
                        if (ci.Num < mincount)
                        {
                            mincount = ci.Num;
                            tempip   = ci.Ip + ":" + ci.Port;
                        }
                    }
                    if (Wptype == WeavePortTypeEnum.Bytes)
                    {
                        p2psev.Send(soc, 0xff, UTF8Encoding.UTF8.GetBytes("jump|" + tempip + ""));
                    }
                    else
                    {
                        p2psev.Send(soc, 0xff, "jump|" + tempip + "");
                    }
                    soc.Close();
                    return;
                }

                //IPEndPoint clientipe = (IPEndPoint)soc.RemoteEndPoint;
                if (Wptype != WeavePortTypeEnum.Bytes)
                {
                    p2psev.Send(soc, 0xff, "token|" + cobj.Token + "");
                }

                GateHelper.SetConnItemlist(ConnItemlist, cobj, Pipeline);

                List <String> listsercer = new List <string>();
                bool          tempb      = true;
                foreach (GateWayCommandItem ci in CommandItemS)
                {
                    tempb = true;
                    foreach (string ser in listsercer)
                    {
                        if (ser == (ci.Ip + ci.Port))
                        {
                            tempb = false;
                            goto lab882;
                        }
                    }
lab882:
                    if (tempb)
                    {
                        if (ci.Client[0, 0, 0, 0] != null)
                        {
                            listsercer.Add(ci.Ip + ci.Port);
                            ci.Client[0, 0, 0, Convert.ToInt32(clientipe.Port.ToString().Substring(clientipe.Port.ToString().Length - 1, 1))].send(0xff, "in|" + cobj.Token);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (EventMylog != null)
                {
                    EventMylog("EventUpdataConnSoc", ex.Message);
                }
            }
        }