示例#1
0
 private void OnLine(UserToken token)
 {
     ExecutorPool.Instance.Execute(delegate()
     {
         Write(token, UserProtocol.ONLINE_SRES, Convert(userBiz.OnLine(token)));
     });
 }
示例#2
0
 /// <summary>
 /// 当用户断开连接时释放链接并存回连接池
 /// </summary>
 public void Push(UserToken token)
 {
     if (token != null)
     {
         _pool.Push(token);              //存回堆栈
     }
 }
示例#3
0
 private void CreateRole(UserToken token, string message)
 {
     ExecutorPool.Instance.Execute(delegate()
     {
         Write(token,UserProtocol.CREATE_SRES,userBiz.CreateRole(token,message));
     });
 }
示例#4
0
        public override void MessageReceive(UserToken token, object message)
        {
            SocketModel model = message as SocketModel;

            switch (model.Type)
            {
                case Protocol.TYPE_LOGIN:
                    login.MessageReceive(token, model);
                    break;
                case Protocol.TYPE_USER:
                    user.MessageReceive(token,model);
                    break;
                case Protocol.TYPE_MATCH:
                    match.MessageReceive(token, model);
                    break;
                case Protocol.TYPE_SELECT:
                    select.MessageReceive(token, model);
                    break;
                case Protocol.TYPE_FIGHT:
                    fight.MessageReceive(token, model);
                    break;
                default:
                    //未知模块可能是客户端作弊了
                    break;
            }
        }
示例#5
0
 public void ClientClose(UserToken token, string error)
 {
     ExecutorPool.Instance.Execute(delegate()
     {
         accountBIZ.Close(token);
     });
 }
示例#6
0
        private Socket _server; //服务器Socket监听对象

        #endregion Fields

        #region Constructors

        /// <summary>
        /// 初始化通信监听
        /// </summary>
        /// <param name="max">最大连接数</param>
        /// <param name="port">监听的端口</param>
        public ServerStart(int max,int port)
        {
            _server = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
            _maxClient = max;                               //实例化socket监听对象

            _pool=new UserTokenPool(max);                   //实例化连接池对象

            //实例化一个最大允许max个线程允许的信号量
            //并将它的计数器的初始值设为max
            //这就是说除了调用该信号量的线程都将被阻塞
            _acceptClients = new Semaphore(max,max);

            //初始化创建max个数的链接对象并存入连接池
            for (var i = 0; i < max; i++)
            {
                //初始化token信息
                var token=new UserToken();

                //绑定接收事件
                token.ReceiveSAEA.Completed+=
                    new EventHandler<SocketAsyncEventArgs>(IO_Comleted);

                //绑定发送事件
                token.SendSAEA.Completed+=
                    new EventHandler<SocketAsyncEventArgs>(IO_Comleted);

                token.LD = LD;
                token.LE = LE;
                token.encode = encode;
                token.decode = decode;
                token.sendProcess = ProccessSend;

                _pool.Push(token);
            }
        }
示例#7
0
 private void GetInfo(UserToken token)
 {
     ExecutorPool.Instance.Execute(delegate()
     {
         Write(token, UserProtocol.INFO_SRES, Convert(userBiz.GetByAccount(token)));
     });
 }
示例#8
0
 /// <summary>
 /// 处理注册
 /// </summary>
 public void Reg(UserToken token, AccountInfoDTO value)
 {
     ExecutorPool.Instance.Execute(
         delegate()
         {
             int result = accountBIZ.Create(token, value.account, value.password);
             Write(token, LoginProtocol.REG_SRES, result);
         });
 }
示例#9
0
        public bool create(NetFrame.UserToken token, string name)
        {
            UserModel userModel = new UserModel();

            userModel.id   = index++;
            userModel.name = name;
            idToModelDict.Add(userModel.id, userModel);
            return(true);
        }
示例#10
0
        /// <summary>
        /// 删除角色坐标
        /// </summary>
        /// <param name="token"></param>
        public void DeletePos(NetFrame.UserToken token)
        {
            int id = userCache.GetUserId(token);

            if (posCache.IsInPosDic(id))
            {
                posCache.DeletePos(id);
            }
        }
示例#11
0
 public void ClientClose(NetFrame.UserToken token, string error)
 {
     ExecutorPool.Instance.execute(
         delegate()
     {
         accountBiz.close(token);
     }
         );
 }
示例#12
0
        public void ClientClose(UserToken token, string error)
        {
            //判断玩家是否在战斗中
            if (userRoom.ContainsKey(GetUserId(token)))
            {
                roomMap[userRoom[GetUserId(token)]].ClientClose(token, error);

            }
        }
示例#13
0
 public void ClientClose(NetFrame.UserToken token, string error)
 {
     //调用离开方法 让此连接不再接收网络消息
     leave(token);
     //通知房间其他人 房间解散了 回主界面去
     brocast(SelectProtocol.DESTORY_BRO, null);
     //通知管理器 移除自身
     EventUtil.destorySelect(GetArea());
 }
示例#14
0
 public int GetUserId(UserToken token)
 {
     UserModel user = GetUser(token);
     if (user == null)
     {
         return -1;
     }
     return user.ID;
 }
示例#15
0
 public void MessageReceive(NetFrame.UserToken token, NetFrame.auto.SocketModel message)
 {
     switch (message.command)
     {
     case ExploreProtocol.INPUT_CREQ:
         Input(message.GetMessage <byte[]>());
         break;
     }
 }
示例#16
0
 public dao.UserModelDao online(NetFrame.UserToken token, int userID)
 {
     if (!idTotoken.ContainsKey(userID))
     {
         idTotoken.Add(userID, token);
         tokenToid.Add(token, userID);
     }
     return(idToModel[userID]);
 }
示例#17
0
        public dao.model.User get(NetFrame.UserToken token)
        {
            if (!has(token))
            {
                return(null);
            }

            return(idToModel[tokenToId[token]]);
        }
示例#18
0
 public void MessageReceive(NetFrame.UserToken token, NetFrame.auto.SocketModel message)
 {
     switch (message.command)
     {
     case FightProtocol.ENTER_CREQ:
         enter(token);
         break;
     }
 }
示例#19
0
 public int getId(NetFrame.UserToken token)
 {
     //判断在线字典中是否有此连接的记录  没有说明此连接没有登陆 无法获取到账号id
     if (!onlineAccMap.ContainsKey(token))
     {
         return(-1);
     }
     //返回绑定账号的id
     return(accMap[onlineAccMap[token]].id);
 }
示例#20
0
 public void ClientClose(NetFrame.UserToken token, string error)
 {
     leave(token);
     if (missionID != -1)
     {
         ScheduleUtil.Instance.removeMission(missionID);
     }
     brocast(SelectProtocol.DESTORY_BRO, null);
     EventUtil.destorySelect(Area);
 }
示例#21
0
 public int getID(NetFrame.UserToken token)
 {
     //判断是否存在连接对象记录,防止非法访问
     if (!onlineAccMap.ContainsKey(token))
     {
         return(-1);
     }
     //返回绑定账号的ID
     return(accMap[onlineAccMap[token]].id);
 }
示例#22
0
 public void offline(NetFrame.UserToken token)
 {
     if (tokenToId.ContainsKey(token))
     {
         if (idToToken.ContainsKey(tokenToId[token]))
         {
             idToToken.Remove(tokenToId[token]);
         }
         tokenToId.Remove(token);
     }
 }
示例#23
0
        public USER getByAccount(NetFrame.UserToken token)
        {
            //帐号是否登陆 获取帐号ID
            int accountId = accBiz.get(token);

            if (accountId == -1)
            {
                return(null);
            }
            return(userCache.getByAccountId(accountId));
        }
示例#24
0
 public void OffLine(UserToken token)
 {
     if (tokenToId.ContainsKey(token))
     {
         if (idToToken.ContainsKey(tokenToId[token]))
         {
             idToToken.Remove(tokenToId[token]);
         }
         tokenToId.Remove(token);
     }
 }
示例#25
0
        public int GetID(NetFrame.UserToken token)
        {
            //玩家不在线则返回-1
            if (!onlineAccMap.ContainsKey(token))
            {
                return(-1);
            }

            //返回账号ID
            return(accMap[onlineAccMap[token]].ID);
        }
示例#26
0
 public void Brocast(byte type, int area, int command, object message, UserToken exToken = null)
 {
     byte[] value = MessageEncoding.MessageEncode(CreateSocketModel(type, area, command, message));
     value = LengthEncoding.Encode(value);
     foreach (UserToken item in userList)
     {
         if (item == exToken) continue;
         byte[] bs = new byte[value.Length]; //防治将元数据变更
         Array.Copy(value, 0, bs, 0, value.Length);
         item.Write(bs);
     }
 }
示例#27
0
 public override void ClientClose(UserToken token, string error)
 {
     //user连接关闭方法,一定要放在逻辑单元后面
     //其他逻辑单元需要通过user绑定数据来进行内存清理
     //如果先清除了绑定关系,其他模块无法获取角色数据会导致无法清理
     Console.WriteLine("客户端断开连接");
     select.ClientClose(token,error);
     match.ClientClose(token,error);
     user.ClientClose(token,error);
     login.ClientClose(token, error);
     fight.ClientClose(token,error);
 }
示例#28
0
 /// <summary>
 /// 用户离开当前子模块
 /// </summary>
 /// <param name="token"></param>
 /// <returns></returns>
 public bool Leave(UserToken token)
 {
     if (userList.Contains(token))
     {
         userList.Remove(token);
         return true;
     }
     else
     {
         return false;
     }
 }
示例#29
0
        /// <summary>
        /// 创建角色初始坐标
        /// </summary>
        /// <param name="token"></param>
        public PosDto CreatePos(NetFrame.UserToken token)
        {
            int id = userCache.GetUserId(token);

            if (!posCache.IsInPosDic(id))
            {
                POS    pos    = posCache.CreatPos(id);
                PosDto posDto = new PosDto(pos.Id, pos.Posx, pos.Posy, pos.Posz, pos.Rotax, pos.Rotay, pos.Rotaz);
                return(posDto);
            }
            return(null);
        }
示例#30
0
 public void MessageReceive(UserToken token, SocketModel message)
 {
     switch (message.Command)
     {
         case MatchProtocol.ENTER_CREQ:
             Enter(token);
             break;
         case MatchProtocol.LEAVE_CREQ:
             Leave(token);
             break;
     }
 }
示例#31
0
 /// <summary>
 /// 用户进入当前子模块
 /// </summary>
 /// <param name="token"></param>
 /// <returns></returns>
 public bool Enter(UserToken token)
 {
     if (userList.Contains(token))
     {
         return false;
     }
     else
     {
         userList.Add(token);
         return true;
     }
 }
示例#32
0
 public void ClientClose(UserToken token, string error)
 {
     int userID = GetUserId(token);
     if (userRoom.ContainsKey(userID))
     {
         int roomID;
         userRoom.TryRemove(userID, out roomID);
         if (roomMap.ContainsKey(roomID))
         {
             roomMap[roomID].ClientClose(token,error);
         }
     }
 }
示例#33
0
 public int Login(UserToken token, string account, string password)
 {
     //账号密码为空,输入不合法
     if (account == null || password == null) return -4;
     //判断账号是否存在
     if (!accountCache.HasAccount(account)) return -1;
     //判断账号是否在线
     if (accountCache.IsOnline(account)) return -2;
     //判断账号密码是否匹配
     if (!accountCache.Match(account, password)) return -3;
     accountCache.Online(token, account);
     return 0;
 }
示例#34
0
        public void MessageReceive(NetFrame.UserToken token, SocketModel message)
        {
            switch (message.Command)
            {
            case LoginProtocol.LOGIN_CREQ:
                Login(token, message.GetMessage <AccountModel>());
                break;

            case LoginProtocol.REG_CREQ:
                Reg(token, message.GetMessage <AccountModel>());
                break;
            }
        }
示例#35
0
        //消息接收
        public void MessageReceive(NetFrame.UserToken token, NetFrame.auto.SocketModel model)
        {
            switch (model.command)
            {
            case LoginProtocol.LOGIN_CREQ:
                login(token, model.GetMessage <AccountInfoDTO>());
                break;

            case LoginProtocol.REG_CREQ:
                reg(token, model.GetMessage <AccountInfoDTO>());
                break;
            }
        }
示例#36
0
        public List <SkillDTO> GetSkillList(NetFrame.UserToken token)
        {
            int userId = UserCache.GetUserId(token);

            if (SkillCache.IsInSkillDic(userId))
            {
                List <SKILL> skillList = SkillCache.GetSkillList(userId);
                return(GetSkillDtoList(skillList));
            }
            else
            {
                return(AddSkill(token));
            }
        }
示例#37
0
        public void MessageReceive(UserToken token, SocketModel message)
        {
            //登录模块没有子模块,所以直接判断命令协议
            switch (message.Command)
            {
                case LoginProtocol.LOGIN_CREQ:
                    Login(token, message.GetMessage<AccountInfoDTO>());
                    break;
                case LoginProtocol.REG_CREQ:
                    Reg(token, message.GetMessage<AccountInfoDTO>());
                    break;

            }
        }
示例#38
0
        public void MessageReceive(NetFrame.UserToken token, NetFrame.auto.SocketModel message)
        {
            switch (message.Command)
            {
            case MatchProtocol.ENTER_CREQ:
                //Console.WriteLine("角色发来匹配请求...");
                enter(token);
                break;

            case MatchProtocol.LEAVE_CREQ:
                //Console.WriteLine("申请取消匹配...");
                leave(token);
                break;
            }
        }
示例#39
0
 public void MessageReceive(UserToken token, SocketModel message)
 {
     switch (message.Command)
     {
         case UserProtocol.CREATE_CREQ:
             CreateRole(token, message.GetMessage<string>());
             break;
         case UserProtocol.INFO_CREQ:
             GetInfo(token);
             break;
         case UserProtocol.ONLINE_CREQ:
             OnLine(token);
             break;
     }
 }
示例#40
0
        /// <summary>
        /// 获取角色坐标
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public PosDto GetPos(NetFrame.UserToken token)
        {
            int id = userCache.GetUserId(token);

            if (posCache.IsInPosDic(id))
            {
                POS    pos    = posCache.GetPos(id);
                PosDto posDto = new PosDto(pos.Id, pos.Posx, pos.Posy, pos.Posz, pos.Rotax, pos.Rotay, pos.Rotaz);
                return(posDto);
            }
            else
            {
                return(CreatePos(token));//如果没有坐标,则创建初始坐标
            }
        }
示例#41
0
 /// <summary>
 /// 客户端断开连接
 /// </summary>
 /// <param name="token">断开连接的用户对象</param>
 /// <param name="error"断开连接的错误编码></param>
 public void ClientClose(UserToken token, string error)
 {
     if (token.conn != null)
     {
         lock (token)
         {
             //通知应用层面,客户端断开连接
             center.ClientClose(token, error);
             token.Close();
             //返回用户池
             pool.Push(token);
             //加回一个信号量,供其他用户使用
             acceptClient.Release();
         }
     }
 }
示例#42
0
        public UserModel OnLine(UserToken token)
        {
            int accountID = accountBiz.Get(token);
            if (accountID == -1)
            {
                return null;
            }

            UserModel user = userCache.GetByAccountID(accountID);
            if (userCache.IsOnLine(user.ID))
            {
                return null;
            }
            userCache.OnLine(token, user.ID);
            return user;
        }
示例#43
0
        public void MessageReceive(NetFrame.UserToken token, NetFrame.Auto.SocketModel message)
        {
            switch (message.command)
            {
            case PosProtocol.GetPos_CREQ:
                GetPos(token);
                break;

            case PosProtocol.UpdatePos_CREQ:
                UpdatePos(token, message.GetMessage <PosDto>());
                break;

            case PosProtocol.DeletePos_CREQ:
                DeletePos(token);
                break;
            }
        }
示例#44
0
        public void ClientClose(UserToken token, string error)
        {
            Leave(token);
            int userID = GetUserId(token);
            if(teamOnes.ContainsKey(userID) || teamTwos.ContainsKey(userID))
            {
                if(!offLine.Contains(userID))
                {
                    offLine.Add(userID);
                }
            }

            if(offLine.Count == enterCount)
            {
                EventUtil.destroyFight(GetArea());
            }
        }
示例#45
0
        public void ClientClose(NetFrame.UserToken token, string error)
        {
            leave(token);
            int userId = getUserId(token);

            if (team.ContainsKey(userId))
            {
                if (!off.Contains(userId))
                {
                    off.Add(userId);
                }
            }
            if (off.Count == heroCount)
            {
                EventUtil.destoryFight(GetArea());
            }
        }
示例#46
0
        public void MessageReceive(NetFrame.UserToken token, NetFrame.auto.SocketModel message)
        {
            switch (message.command)
            {
            case UserProtocol.CREATE_CREQ:
                create(token, message.GetMessage <string>());
                break;

            case UserProtocol.INFO_CREQ:
                info(token);
                break;

            case UserProtocol.ONLINE_CREQ:
                online(token);
                break;
            }
        }
示例#47
0
        public bool CreateRole(UserToken token, string name)
        {
            //账号是否登录 获取账号ID
            int accountID = accountBiz.Get(token);
            if (accountID == -1)
            {
                return false;
            }
            //判断当前是否已经拥有角色
            if (userCache.HasByAccountId(accountID))
            {
                return false;
            }

            userCache.CreateRole(token, name, accountID);
            return true;
        }
示例#48
0
        public bool Create(NetFrame.UserToken token, string name)
        {
            //帐号是否登陆 获取帐号ID
            int accountId = accBiz.get(token);

            if (accountId == -1)
            {
                return(false);
            }
            //判断当前帐号是否已经拥有角色
            if (userCache.hasByAccountId(accountId))
            {
                return(false);
            }
            userCache.create(token, name, accountId);
            return(true);
        }
示例#49
0
 public void MessageReceive(UserToken token, SocketModel message)
 {
     switch (message.Command)
     {
         case FightProtocol.ENTER_CREQ:
             Enter(token);
             break;
         case FightProtocol.MOVE_CREQ:
             Move(token,message.GetMessage<MoveDTO>());
             break;
         case FightProtocol.ATTACK_CREQ:
             Attack(token,message.GetMessage<int>());
             break;
         case FightProtocol.DAMAGE_CREQ:
             Damage(token, message.GetMessage<DamageDTO>());
             break;
     }
 }
示例#50
0
 public bool CreateRole(UserToken token, string name, int accountID)
 {
     UserModel user = new UserModel();
     user.Name = name;
     user.ID = index++;
     user.AccountID = accountID;
     List<int> list = new List<int>();
     for (int i = 1; i < 8; i++)
     {
         list.Add(i);
     }
     user.HeroList = list;
     //创建成功后进行账户ID和用户ID的绑定
     accToUid.Add(accountID,user.ID);
     //创建成功后进行用户ID和账户ID的绑定
     idToModel.Add(user.ID,user);
     return true;
 }
示例#51
0
        public bool create(NetFrame.UserToken token, string name, int accountId)
        {
            USER user = new USER();

            user.name      = name;
            user.accountId = accountId;
            List <int> list = new List <int>();

            for (int i = 1; i < 9; i++)
            {
                list.Add(i);
            }
            user.heroList = list.ToArray();
            user.Add();
            //创建成功 进行帐号ID和用户ID的绑定
            accToUid.Add(accountId, user.id);
            //创建成功 进行用户ID和用户模型的绑定
            idToModel.Add(user.id, user);
            return(true);
        }
示例#52
0
文件: MapRoom.cs 项目: hehay/MyServer
        public void MessageReceive(NetFrame.UserToken token, NetFrame.Auto.SocketModel message)
        {
            switch (message.command)
            {
            case MapProtocol.EnterMap_CREQ:
                EnterMap(token, message.GetMessage <UserDTO>());
                break;

            case MapProtocol.LeaveMap_CREQ:
                LeaveMap(token);
                break;

            case MapProtocol.Move_CREQ:
                Move(token, message.GetMessage <MoveDto>());
                break;

            case MapProtocol.Attack_CREQ:
                Attack(token, message.GetMessage <int[]>());
                break;

            case MapProtocol.Damage_CREQ:
                Damage(token, message.GetMessage <DamageDTO>());
                break;

            case MapProtocol.Skill_CREQ:
                Skill(token, message.GetMessage <SkillAttackDTO>());
                break;

            case MapProtocol.UseInventory_CREQ:
                UseInventory(token, message.GetMessage <int>());
                break;

            case MapProtocol.UnUseInventory_CREQ:
                UnUseInventory(token, message.GetMessage <int>());
                break;

            case MapProtocol.Talk_CREQ:
                Talk(token, message.GetMessage <TalkDTO>());
                break;
            }
        }
示例#53
0
        public void MessageReceive(NetFrame.UserToken token, NetFrame.Auto.SocketModel message)
        {
            switch (message.command)
            {
            case SkillProtocol.GetskillList_CREQ:
                GetSkillLit(token);
                break;

            case SkillProtocol.Deleteskill_CREQ:
                DeleteSkill(token);
                break;

            case SkillProtocol.SkillUp_CREQ:
                SkillUp(token, message.GetMessage <int>());
                break;

            case SkillProtocol.Updateskill_CREQ:
                UpDateSkill(token, message.GetMessage <SkillDTO>());
                break;
            }
        }
        public void MessageReceive(NetFrame.UserToken token, NetFrame.auto.SocketModel message)
        {
            switch (message.command)
            {
            case SelectProtocol.ENTER_CREQ:
                enter(token);
                break;

            case SelectProtocol.SELECT_CREQ:
                select(token, message.GetMessage <int>());
                break;

            case SelectProtocol.TALK_CREQ:
                talk(token, message.GetMessage <string>());
                break;

            case SelectProtocol.READY_CREQ:
                ready(token);
                break;
            }
        }
示例#55
0
        public bool creat(NetFrame.UserToken token, string name, int accountID)
        {
            UserModelDao user = new UserModelDao();

            user.id = index;
            index++;
            user.name      = name;
            user.accountID = accountID;
            //向缓存中添加
            accTouid.Add(accountID, user.id);
            idToModel.Add(user.id, user);

            for (int i = 0; i < 10; i++)
            {
                user.heroList.Add(i + 1);
            }

            //继续向数据库中添加
            //TODO
            return(true);
        }
示例#56
0
        public void MessageReceive(NetFrame.UserToken token, NetFrame.auto.SocketModel message)
        {
            switch (message.command)
            {
            case ExploreProtocol.ENTER_CREQ:
                enter(token, message.area);
                break;

            case ExploreProtocol.INFORM_CREQ:
                inform(token, message.area);
                break;

            case ExploreProtocol.LEAVE_CREQ:
                leave(token);
                break;

            default:
                roomMap[userRoom[getUserId(token)]].MessageReceive(token, message);
                break;
            }
        }
示例#57
0
 /// <summary>
 /// 客户端断开连接
 /// </summary>
 /// <param name="token">断开的用户对象</param>
 /// <param name="error">断开连接的错误编码</param>
 public void ClientClose(UserToken token, string error)
 {
     if (token.Conn != null)
     {
         lock (token)
         {
             //通知应用层客户端断开连接
             token.Close();
             //将连接还给连接池
             _pool.Push(token);
             //释放信号量,加回一个供其他用户使用
             _acceptClients.Release();
         }
     }
 }
示例#58
0
 public void StartReceive(UserToken token)
 {
     //用户连接对象,开启异步数据接收
     bool result=token.Conn.ReceiveAsync(token.ReceiveSAEA);
     //检测异步事件是否挂起
     if (!result)
     {
         ProcessReceive(token.ReceiveSAEA);
     }
 }
示例#59
0
        /// <summary>
        /// 初始化对象池
        /// </summary>
        /// <param name="max">连接数</param>
        private void InitTokenPool(int max)
        {
            pool = new UserTokenPool(max); //创建连接池
            acceptClient = new Semaphore(max, max); //连接信号量,初始化数量和最大连接数量

            //在初始化的时候就将连接对象依次创建,好处:省去了连接时候创建,断开时销毁的过程,坏处:服务器连接空余较多
            for (int i = 0; i < max; i++)
            {
                UserToken token = new UserToken();
                //初始化token信息
                token.receiveSAEA.Completed += new EventHandler<SocketAsyncEventArgs>(IO_Completed);
                token.sendSAEA.Completed += new EventHandler<SocketAsyncEventArgs>(IO_Completed);
                token.lengthEncode = lengthEncode;
                token.lengthDecode = lengthDecode;
                token.messageEncode = messageEncode;
                token.messageDecode = messageDecode;
                token.sendProcess = ProcessSend;
                token.closeProcess = ClientClose;
                token.center = center;

                pool.Push(token);
            }
        }
示例#60
0
        /// <summary>
        /// 开始接收数据
        /// </summary>
        /// <param name="token"></param>
        public void StartReceive(UserToken token)
        {
            try
            {

                //用户连接对象,开启异步数据接收,必须设置接收对象的缓冲区大小
                bool result = token.conn.ReceiveAsync(token.receiveSAEA);

                //异步事件是否挂起
                if (!result)
                {
                    ProcessReceive(token.receiveSAEA);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }