Ejemplo 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
                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();
                _pomeloClient._processMessage(_messageProtocol.decode(pkg.body));
            }
            else if (pkg.type == PackageType.PKG_KICK)
            {
                this.getPomeloClient().Disconnect();
                this.close();
            }
        }
        public static void protocolProcess(byte[] bytes)
        {
            JsonObject dict = new JsonObject();
            JsonObject serverProtos = new JsonObject();
            JsonObject clientProtos = new JsonObject();

            MessageProtocol messageProtocol = new MessageProtocol(dict, serverProtos, clientProtos);
            Package pkg = PackageProtocol.decode(bytes);

            messageProtocol.decode(pkg.body);
        }