/// <summary> /// 解封包 /// </summary> /// <param name="callback"></param> internal void Decode(Action <Packet> callback) { UserTokenSession UserToken = this.UserToken as UserTokenSession; int offset = 0; var curBytes = MemoryBuffer.Span; while (offset < BytesTransferred) { try { //测试服务端解析二进制流出现问题 //if (UserToken.Mode == SocketMode.Server) // throw new Exception(); offset += UserToken.Cache.LoadHead(curBytes.Slice(offset)); offset += UserToken.Cache.LoadBody(curBytes.Slice(offset)); } catch { UserToken.SendReconnect(); return; } if (UserToken.Cache.IsCompleted()) { PacketCommand(callback); } } }
void SocketReconect() { UserTokenSession UserToken = this.UserToken as UserTokenSession; switch (UserToken.Mode) { case ApplyMode.Server: UserToken.SendReconnect(); break; case ApplyMode.Client: UserToken.Channel.Disconnect(true); UserToken.ShakeHandEvent.ReConnect(); break; } }