コード例 #1
0
        public override void ChannelRead(IChannelHandlerContext context, object message)
        {
            SafeProcess(() =>
            {
                var msg = (Message)message;
                //补充来源信息
                msg.Origin = RemoteSession.GetUnicastAddress(context.Channel);

                //找到发送者在服务器端的回话对象
                var senders = this.Sessions.GetSessions(msg.Origin);
                foreach (var sender in senders)
                {
                    using (var temp = HandlerContext.Pool.Borrow())
                    {
                        var ctx = temp.Item;
                        if (sender.IsActive)
                        {
                            this.Server.StartProcess(sender, msg, ctx);
                        }

                        if (!ctx.IsCompleted && sender.IsActive)
                        {
                            Process(sender, msg, ctx);
                        }

                        //使用服务器扩展的handler处理
                        if (sender.IsActive)
                        {
                            this.Server.EndProcess(sender, msg, ctx);
                        }
                    }
                }
            }, context);
        }
コード例 #2
0
        public RemoteSession GetSession(IChannel channel)
        {
            var sessions = this.GetSessions(RemoteSession.GetUnicastAddress(channel)).OfType <RemoteSession>();

            foreach (var session in sessions)
            {
                if (session.Channel == channel)
                {
                    return(session);
                }
            }
            return(null);
        }
コード例 #3
0
        public override void ChannelRead(IChannelHandlerContext context, object message)
        {
            SafeProcess(() =>
            {
                var msg = (Message)message;
                //补充来源信息
                msg.Origin = RemoteSession.GetUnicastAddress(context.Channel);

                //找到发送者在服务器端的回话对象
                var senders = this.Sessions.GetSessions(msg.Origin);
                foreach (var sender in senders)
                {
                    Process(sender, msg);

                    //使用服务器扩展的handler处理
                    if (sender.IsActive)
                    {
                        this.Server.Process(sender, msg);
                    }
                }
            }, context);
        }
コード例 #4
0
        /// <summary>
        /// 会话上线
        /// </summary>
        /// <param name="session"></param>
        /// <param name="package"></param>
        protected void Online(IChannelHandlerContext ctx)
        {
            var session = new RemoteSession(ctx.Channel);

            this.Sessions.Add(session);
        }