Beispiel #1
0
 public bool IsCancleSend(ClientData dat)
 {
     //判断是否为对应取消的SEND
     return(dat.Type == CLIENT_TYPE.SEND && ID == dat.ID);
 }
Beispiel #2
0
        public void AddRecvData(ClientData dat)
        {
            //判断数据
            switch (dat.Type)
            {
            case ClientData.CLIENT_TYPE.IMPULSE:
            {
                //脉冲信号
                dat.CreateImpulseRecv();  //转换为回复信号
                AddSendData(dat);         //添加到发送列表
                return;
            }

            case ClientData.CLIENT_TYPE.IMPULSE_RECV:
            {
                //脉冲回复信号
                //计算延迟
                var time     = DateTime.Now;
                int dataTime = (time.Minute * 60000) + (time.Second * 1000) + (time.Millisecond) + 3600000;
                delay     = (dataTime - dat.GetImpulseTime()) % 3600000;
                delayTime = sw.ElapsedMilliseconds;
                return;
            }

            case ClientData.CLIENT_TYPE.SEND_ONCE:
            {
                break;
            }

            case ClientData.CLIENT_TYPE.SEND:
            {
                //检查发送列表是否有RECV_SEND
                if (AddRecvSend(dat) == false)
                {
                    //已经存在
                    return;
                }
                else
                {
                    //不存在
                    //检查是否已经接收
                    //Console.WriteLine("ID:"+dat.ID);
                    if (CheckRecvID(dat.ID) == true)
                    {
                        return;
                    }

                    /*
                     * {
                     *  for (int i = 0; i < RecvIDList.Count; i++)
                     *  {
                     *      var l = RecvIDList[i];
                     *      Console.Write(l.minID + "-" + l.maxID + "");
                     *  }
                     *  Console.WriteLine();
                     * }//*/
                    //检查是否在接收列表
                    if (CheckRecvExist(dat))
                    {
                        return;
                    }
                }
                break;
            }

            case ClientData.CLIENT_TYPE.RECV_SEND:
            {
                CancleSend(dat);
                return;
            }

            case ClientData.CLIENT_TYPE.RECV_RECV_SEND:
            {
                return;
            }

            default:
                return;
            }

            //将数据添加到数据接收列表
            lock (lockRecvList)
            {
                RecvList.Add(dat);
            }
        }
Beispiel #3
0
 public bool Equal(ClientData dat)
 {
     return(dat.ID == ID && dat.Type == Type);
 }
Beispiel #4
0
        private void Callback(IAsyncResult ar)
        {
            //接收回调函数
            if (isConnect == false)
            {
                return;
            }

            var ep = new IPEndPoint(IPAddress.Any, 0);

            //读取数据
            byte[] bytes = Client.EndReceive(ar, ref ep);
            var    dat   = new ClientData(ep, bytes);

            //Console.WriteLine(dat.ToString());

            //重新开始接收
            Client.BeginReceive(new AsyncCallback(Callback), null);

            //是否为登录消息
            if (dat.IsSignIn())
            {
                int    i           = 0;
                int    t           = -1;
                bool   IsReConnect = false;
                int    index       = 4;
                string qq          = GlobalC.GetSendData_Str(dat.Data, ref index);
                string exid        = GlobalC.GetSendData_Str(dat.Data, ref index);
                foreach (var client in clients)
                {
                    if (client.EqualQQ(qq, exid))
                    {
                        client.ReConnect(ep);
                        IsReConnect = true;
                        client.AddRecvData(dat);
                        client.SetQQ(qq);
                        client.SetExID(exid);
                        break;
                    }
                    else
                    {
                        if (t == -1 && client.IsConnect() == false)
                        {
                            t = i;
                        }
                    }
                    i++;
                }
                if (IsReConnect == false && t != -1)
                {
                    clients[t].AddConnect(ep);
                    clients[t].AddRecvData(dat);
                    clients[t].SetQQ(qq);
                    clients[t].SetExID(exid);
                }
            }
            else
            {
                foreach (var client in clients)
                {
                    //判断ip
                    if (client.EqualIP(ep) && client.IsConnect())
                    {
                        //添加到消息列表
                        client.AddRecvData(dat);
                    }
                }
            }
            RecvNum++;
        }