Пример #1
0
        protected override void OnReceive(ReceivedEventArgs e)
        {
            LastActive = DateTime.Now;

            // Api解码消息得到Action和参数
            var msg = e.Message as IMessage;

            if (msg == null || msg.Reply)
            {
                return;
            }

            // 连接复用
            if (_Host is ApiServer svr && svr.Multiplex)
            {
                // 如果消息使用了原来SEAE的数据包,需要拷贝,避免多线程冲突
                // 也可能在粘包处理时,已经拷贝了一次
                if (e.Packet != null)
                {
                    if (msg.Payload != null && e.Packet.Data == msg.Payload.Data)
                    {
                        msg.Payload = msg.Payload.Clone();
                    }
                }

                ThreadPoolX.QueueUserWorkItem(m =>
                {
                    var rs = _Host.Process(this, m);
                    if (rs != null && Session != null && !Session.Disposed)
                    {
                        Session?.SendMessage(rs);
                    }
                }, msg);
            }
Пример #2
0
        protected override void OnReceive(ReceivedEventArgs e)
        {
            LastActive = DateTime.Now;

            // Api解码消息得到Action和参数
            var msg = e.Message as IMessage;

            if (msg == null || msg.Reply)
            {
                return;
            }

            // 连接复用
            if (_Host is ApiServer svr && svr.Multiplex)
            {
                ThreadPoolX.QueueUserWorkItem(m =>
                {
                    var rs = _Host.Process(this, m);
                    if (rs != null)
                    {
                        Session?.SendMessage(rs);
                    }
                }, msg);
            }