Example #1
0
        public virtual void OnReceived(string data)
        {
            try
            {
                MessageBag msgBag = Newtonsoft.Json.JsonConvert.DeserializeObject <MessageBag>(data);
                mCurrentBag = msgBag;

                if (this.Session == null)
                {
                    if (msgBag.SessionID.IsNullOrEmpty())
                    {
                        this.Session = SessionState.GetSession(Guid.NewGuid().ToString());
                    }
                    else
                    {
                        this.Session = SessionState.GetSession(msgBag.SessionID);
                        if (this.Session == null)
                        {
                            this.Session = SessionState.GetSession(Guid.NewGuid().ToString());
                        }
                    }
                }

                if (msgBag.Action == "init")
                {
                    handleInit(msgBag);
                }
                else if (msgBag.Action == "exit")
                {
                    mCloseStreamHandler();
                }
                else if (msgBag.Action == "UploadFile")
                {
                    this.StreamType = RemotingStreamType.Bytes;
                    handleUploadFile(msgBag);
                }
                else if (msgBag.Action == "w_heart")//websocket心跳包
                {
                    SendClientMessage("1", 2);
                    return;
                }
                else if (msgBag.Action == "w_msg")//websocket消息
                {
                    RemotingController.MessageReceive(this.Session, msgBag.State);
                    return;
                }
                else if (msgBag.MethodName.IsNullOrEmpty() == false)
                {
                    handleMethodInvoke(msgBag);
                }
                else if (msgBag.GroupName.IsNullOrEmpty() == false)
                {
                    this.GroupName = msgBag.GroupName;
                    if (RemotingController.MessageReceiverConnect(this.Session, this.GroupName) == false)
                    {
                        throw new Exception("服务器拒绝你接收信息");
                    }
                    KeepAliveHandlers.Add(this);
                    return;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }