Exemplo n.º 1
0
        //Invoke by Transporter, process the message
        internal void processMessage(byte[] bytes)
        {
            Package pkg = PackageProtocol.decode(bytes);

            //Ignore all the message except handshading at handshake stage
            if (pkg.type == PackageType.PKG_HANDSHAKE && this.state == ProtocolState.handshaking)
            {
                //Ignore all the message except handshading
                JsonNode_Object data = (JsonNode_Object)MyJson.MyJson.Parse(Encoding.UTF8.GetString(pkg.body));

                processHandshakeData(data);

                this.state = ProtocolState.working;
            }
            else if (pkg.type == PackageType.PKG_HEARTBEAT && this.state == ProtocolState.working)
            {
                this.heartBeatService.resetTimeout();
            }
            else if (pkg.type == PackageType.PKG_DATA && this.state == ProtocolState.working)
            {
                this.heartBeatService.resetTimeout();
                pc.processMessage(messageProtocol.decode(pkg.body));
            }
            else if (pkg.type == PackageType.PKG_KICK)
            {
                this.getPomeloClient().disconnect();
                this.close();
            }
        }
Exemplo n.º 2
0
        //Invoke by Transporter, process the message
        void processMessage(byte[] bytes)
        {
            Package pkg = PackageProtocol.decode(bytes);

            //Ignore all the message except handshading at handshake stage
            if (pkg.type == PackageType.PKG_HANDSHAKE && this.state == ProtocolState.handshaking)
            {
                //Ignore all the message except handshading
                JsonData data = LitJson.JsonMapper.ToObject(Encoding.UTF8.GetString(pkg.body));

                processHandshakeData(data);

                this.state = ProtocolState.working;
            }
            else if (pkg.type == PackageType.PKG_HEARTBEAT && this.state == ProtocolState.working)
            {
                this.heartBeatService.resetTimeout();
            }
            else if (pkg.type == PackageType.PKG_DATA && this.state == ProtocolState.working)
            {
                this.heartBeatService.resetTimeout();
                if (messageProcessor != null)
                {
                    messageProcessor(messageProtocol.decode(pkg.body));
                }
            }
            else if (pkg.type == PackageType.PKG_KICK)
            {
                this.close();
            }
        }
Exemplo n.º 3
0
        //Invoke by Transporter, process the message
        internal void processMessage(byte[] bytes)
        {
            Package pkg = PackageProtocol.decode(bytes);

            //Ignore all the message except handshading at handshake stage
            if (pkg.type == PackageType.PKG_HANDSHAKE && this.state == ProtocolState.handshaking)
            {
                //Ignore all the message except handshading
                JsonObject data = (JsonObject)SimpleJson.SimpleJson.DeserializeObject(Encoding.UTF8.GetString(pkg.body));
                //UnityEngine.Debug.Log (">>PKG_HANDSHAKE: "+data);

                processHandshakeData(data);

                this.state = ProtocolState.working;
            }
            else if (pkg.type == PackageType.PKG_HEARTBEAT && this.state == ProtocolState.working)
            {
                this.heartBeatService.resetTimeout();
                //UnityEngine.Debug.Log (">>PKG_HEARTBEAT: ");
            }
            else if (pkg.type == PackageType.PKG_DATA && this.state == ProtocolState.working)
            {
                //UnityEngine.Debug.Log (">>PKG_DATA: "+KcpTransporter.print(pkg.body));
                Message msg = messageProtocol.decode(pkg.body);
                //UnityEngine.Debug.Log (">>PKG_DATA2: "+(msg==null?"null":msg.type+", "+msg.route+", "+msg.data));
                this.heartBeatService.resetTimeout();
                pc.processMessage(msg);
            }
            else if (pkg.type == PackageType.PKG_KICK)
            {
                //UnityEngine.Debug.Log (">>PKG_KICK: ");
                this.getPomeloClient().disconnect();
                this.close();
            }
        }
        //Invoke by Transporter, process the message
        internal void processMessage(byte[] bytes)
        {
            Package pkg = PackageProtocol.decode(bytes);

            Trace.TraceInformation("processMessage:" + pkg.type + " " + this.state);
            //Ignore all the message except handshading at handshake stage
            if (pkg.type == PackageType.PKG_HANDSHAKE && this.state == ProtocolState.handshaking)
            {
                //Ignore all the message except handshading
                JsonObject data = (JsonObject)SimpleJson.SimpleJson.DeserializeObject(Encoding.UTF8.GetString(pkg.body));

                processHandshakeData(data);

                this.state = ProtocolState.working;
            }
            else if (pkg.type == PackageType.PKG_HEARTBEAT && this.state == ProtocolState.working)
            {
                this.heartBeatService.resetTimeout();
            }
            else if (pkg.type == PackageType.PKG_DATA && this.state == ProtocolState.working)
            {
                this.heartBeatService.resetTimeout();
                pc.processMessage(messageProtocol.decode(pkg.body));
            }
            else if (pkg.type == PackageType.PKG_KICK)
            {
                Trace.TraceInformation("pkg.type == PackageType.PKG_KICK");
                this.getPomeloClient().Kick();
                this.close();
            }
        }
Exemplo n.º 5
0
        //Invoke by Transporter, process the message
        internal void processMessage(byte[] bytes)
        {
            Package pkg = PackageProtocol.decode(bytes);

            //Ignore all the message except handshading at handshake stage
            if (pkg.type == PackageType.PKG_HANDSHAKE && this.state == ProtocolState.handshaking)
            {
                //Ignore all the message except handshading
                string     pkg_body = Encoding.UTF8.GetString(pkg.body);
                JsonObject data     = (JsonObject)SimpleJson.SimpleJson.DeserializeObject(pkg_body);
                processHandshakeData(data);
                this.state = ProtocolState.working;
            }
            else if (pkg.type == PackageType.PKG_HEARTBEAT && this.state == ProtocolState.working)
            {
                this.heartBeatService.resetTimeout();
            }
            else if (pkg.type == PackageType.PKG_DATA && this.state == ProtocolState.working)
            {
                this.heartBeatService.resetTimeout();
                Message msg = messageProtocol.decode(pkg.body);
                pc.processMessage(msg);
            }
            else if (pkg.type == PackageType.PKG_KICK)
            {
                this.close();
            }
        }
Exemplo n.º 6
0
        internal void processMessage(byte[] bytes)
        {
            Package package = PackageProtocol.decode(bytes);

            if ((package.type == PackageType.PKG_HANDSHAKE) && (this.state == ProtocolState.handshaking))
            {
                Encoding.UTF8.GetString(package.body);
                JsonObject msg = (JsonObject)SimpleJson.DeserializeObject(Encoding.UTF8.GetString(package.body));
                this.processHandshakeData(msg);
                this.state = ProtocolState.working;
            }
            else if ((package.type == PackageType.PKG_HEARTBEAT) && (this.state == ProtocolState.working))
            {
                this.heartBeatService.resetTimeout();
            }
            else if ((package.type == PackageType.PKG_DATA) && (this.state == ProtocolState.working))
            {
                this.heartBeatService.resetTimeout();
                this.pc.processMessage(this.messageProtocol.decode(package.body));
            }
            else if (package.type == PackageType.PKG_KICK)
            {
                this.close();
            }
        }
Exemplo n.º 7
0
        //Invoke by Transporter, process the message
        internal void processMessage(byte[] bytes)
        {
            Package pkg = PackageProtocol.decode(bytes);

            //Ignore all the message except handshading at handshake stage
            if (pkg.type == PackageType.PKG_HANDSHAKE && this.state == ProtocolState.handshaking)
            {
                //Ignore all the message except handshading
                JsonObject data = (JsonObject)SimpleJson.SimpleJson.DeserializeObject(Encoding.UTF8.GetString(pkg.body));

                processHandshakeData(data);

                this.state = ProtocolState.working;
            }
            else if (pkg.type == PackageType.PKG_HEARTBEAT && this.state == ProtocolState.working)
            {
                this.heartBeatService.resetTimeout();
            }
            else if (pkg.type == PackageType.PKG_DATA && this.state == ProtocolState.working)
            {
                this.heartBeatService.resetTimeout();
                pc.processMessage(messageProtocol.decode(pkg.body));
            }
            else if (pkg.type == PackageType.PKG_KICK)
            {
                this.close();
                pc.getEventManger().InvokeOnEvent(PomeloClient.EVENT_KICK, null);
            }
        }
Exemplo n.º 8
0
 internal void processMessage(byte[] bytes)
 {
     Package package = PackageProtocol.decode(bytes);
     if (package.type == PackageType.PKG_HANDSHAKE && this.state == ProtocolState.handshaking)
     {
         this.processHandshakeData((JsonObject)SimpleJson.SimpleJson.DeserializeObject(Encoding.UTF8.GetString(package.body)));
         this.state = ProtocolState.working;
     }
     else if (package.type == PackageType.PKG_HEARTBEAT && this.state == ProtocolState.working)
         this.heartBeatService.resetTimeout();
     else if (package.type == PackageType.PKG_DATA && this.state == ProtocolState.working)
     {
         this.heartBeatService.resetTimeout();
         this.pc.processMessage(this.messageProtocol.decode(package.body));
     }
     else
     {
         if (package.type != PackageType.PKG_KICK)
             return;
         this.getPomeloClient().disconnect();
         this.close();
     }
 }