예제 #1
0
 /// <summary>
 /// 推送请求内容到客户端
 /// </summary>
 /// <param name="session">会话</param>
 /// <param name="request">请求</param>
 /// <returns></returns>
 private bool PushRequest(FastSession session, HttpRequest request)
 {
     try
     {
         session.InvokeApi("OnHttpRequest", request.Url.PathAndQuery, request.Body);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
예제 #2
0
 /// <summary>
 /// 推送请求内容到客户端
 /// </summary>
 /// <param name="session">会话</param>
 /// <param name="request">请求</param>
 /// <returns></returns>
 private bool PushRequest(FastSession session, HttpRequest request)
 {
     try
     {
         session.InvokeApi("OnHttpRequest", request.Url.PathAndQuery, request.Body);
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
예제 #3
0
        /// <summary>
        /// 处理断开连接
        /// </summary>
        /// <param name="channel"></param>
        internal void onDisconnect(IChannel channel)
        {
            Console.WriteLine("channel disconnect");
            FastSession fs = null;

            if (allSessions.ContainsKey(channel.Id.AsLongText()))
            {
                //
                allSessions.TryRemove(channel.Id.AsLongText(), out fs);
                fs.Close();
            }
        }
예제 #4
0
        /// <summary>
        /// 连接事件
        /// </summary>
        /// <param name="channel"></param>
        internal void onConnect(IChannel channel)
        {
            FastSession fs = null;

            if (!allSessions.ContainsKey(channel.Id.AsLongText()))
            {
                fs = new FastSession(channel, this);
                if (allSessions.TryAdd(channel.Id.AsLongText(), fs))
                {
                }
            }
        }
예제 #5
0
        internal async void ProcessPacketAsync(IChannel channel, FastPacket packet)
        {
            FastSession fs = null;

            if (allSessions.ContainsKey(channel.Id.AsLongText()))
            {
                fs = allSessions[channel.Id.AsLongText()];
            }
            else
            {
                fs = new FastSession(channel, this);
                allSessions.TryAdd(channel.Id.AsLongText(), fs);
            }
            var requestContext = new RequestContext(fs, packet);

            this.OnRecvFastPacketAsync(requestContext);
        }
예제 #6
0
        /// <summary>
        /// 接收到会话断开连接
        /// </summary>
        /// <param name="session">会话</param>
        protected override void OnDisconnect(FastSession session)
        {
            var log = string.Format("Time:{0} Client:{1} Action:{2} Message:{3}", DateTime.Now.ToString("mm:ss"), session, "Disconnect", "ConnectCount(" + this.AllSessions.Count() + ")");

            Console.WriteLine(log);
        }
예제 #7
0
 /// <summary>
 /// 接收到会话断开连接
 /// </summary>
 /// <param name="session">会话</param>
 protected override void OnDisconnect(FastSession session)
 {
     var log = string.Format("Time:{0} Client:{1} Action:{2} Message:{3}", DateTime.Now.ToString("mm:ss"), session, "Disconnect", "ConnectCount(" + this.AllSessions.Count() + ")");
     Console.WriteLine(log);
 }
예제 #8
0
 protected override void OnDisconnect(FastSession session)
 {
     base.OnDisconnect(session);
 }
예제 #9
0
 /// <summary>
 /// 请求上下文
 /// </summary>
 /// <param name="session">当前会话对象</param>
 /// <param name="packet">数据包对象</param>
 /// <param name="allSessions">所有会话对象</param>
 internal RequestContext(FastSession session, FastPacket packet, IEnumerable<FastSession> allSessions)
 {
     this.Session = session;
     this.Packet = packet;
     this.AllSessions = allSessions;
 }
예제 #10
0
        /// <summary>
        /// 收到fast请求
        /// </summary>
        /// <param name="context">上下文</param>
        /// <returns></returns>
        private Task OnFastRequest(IContenxt context)
        {
            var fastPacket = default(FastPacket);
            if (FastPacket.Parse(context.Buffer, out fastPacket) == false)
            {
                return this.Next.Invoke(context);
            }

            if (fastPacket == null)
            {
                return new Task(() => { });
            }

            if (context.Session.Protocol == null)
            {
                var wrapper = new FastSession(context.Session, this);
                context.Session.SetProtocolWrapper("fast", wrapper);
            }

            var fastSession = (FastSession)context.Session.Wrapper;
            var fastPackets = this.GenerateFastPackets(context, fastPacket);

            return new Task(() =>
            {
                foreach (var packet in fastPackets)
                {
                    var requestContext = new RequestContext(fastSession, packet, context.AllSessions);
                    this.OnRecvFastPacket(requestContext);
                }
            });
        }
예제 #11
0
 /// <summary>
 /// 请求上下文
 /// </summary>
 /// <param name="session">当前会话对象</param>
 /// <param name="packet">数据包对象</param>
 /// <param name="allSessions">所有会话对象</param>
 internal RequestContext(FastSession session, FastPacket packet, ISessionManager allSessions)
 {
     this.Session     = session;
     this.Packet      = packet;
     this.AllSessions = allSessions;
 }
예제 #12
0
 protected override void OnDisconnect(FastSession session)
 {
     base.OnDisconnect(session);
 }
예제 #13
0
 /// <summary>
 /// 请求上下文
 /// </summary>
 /// <param name="session">当前会话对象</param>
 /// <param name="packet">数据包对象</param>
 /// <param name="allSessions">所有会话对象</param>
 internal RequestContext(FastSession session, FastPacket packet, ISessionProvider allSessions)
 {
     this.Session = session;
     this.Packet = packet;
     this.AllSessions = allSessions;
 }
예제 #14
0
 /// <summary>
 /// 异常时
 /// </summary>
 /// <param name="sessionWrapper">产生异常的会话</param>
 /// <param name="context">上下文</param>
 protected virtual void OnException(FastSession sessionWrapper, ExceptionContext context)
 {
     Common.SendRemoteException(sessionWrapper.channel, context);
 }