Example #1
0
        // Invoke by Transporter, process the message
        public void ProcessMessage(byte[] bytes)
        {
            Package pkg = PackageProtocol.Decode(bytes);

            Loom.DispatchToMainThread(() =>
            {
                // 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));

                    this.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();
                    this.pc.ProcessMessage(this.messageProtocol.Decode(pkg.Body));
                }
                else if (pkg.Type == PackageType.PKG_KICK)
                {
                    this.GetPomeloClient().Kick();
                    this.Close();
                }
            });
        }