Ejemplo n.º 1
0
 internal void send(PackageType type)
 {
     if (this.state != ProtocolState.closed)
     {
         this.transporter.send(PackageProtocol.encode(type));
     }
 }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
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();
                }
            });
        }
Ejemplo n.º 4
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();
            }
        }
Ejemplo 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
                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();
            }
        }
Ejemplo n.º 6
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();
            }
        }
        //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();
            }
        }
Ejemplo n.º 8
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();
            }
        }
Ejemplo n.º 9
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();
            }
        }
Ejemplo n.º 10
0
 internal void send(PackageType type)
 {
     if (this._state == ProtocolState.closed)
     {
         return;
     }
     _transporter.send(PackageProtocol.encode(type));
 }
Ejemplo n.º 11
0
 public void send(PackageType type)
 {
     if (this.state == ProtocolState.closed)
     {
         return;
     }
     transporter.send(PackageProtocol.encode(type));
 }
Ejemplo n.º 12
0
 internal void send(PackageType type, byte[] body)
 {
     if (this.state != ProtocolState.closed)
     {
         byte[] buffer = PackageProtocol.encode(type, body);
         this.transporter.send(buffer);
     }
 }
 internal void send(PackageType type)
 {
     if (this.state == ProtocolState.closed)
     {
         return;
     }
     Trace.TraceInformation("send " + type);
     transporter.send(PackageProtocol.encode(type));
 }
Ejemplo n.º 14
0
        // Send message use the transporter
        public void Send(PackageType type, byte[] body)
        {
            if (this.state == ProtocolState.closed)
            {
                return;
            }

            byte[] pkg = PackageProtocol.Encode(type, body);
            this.transporter.Send(pkg);
        }
Ejemplo n.º 15
0
        //Send message use the transporter
        internal void send(PackageType type, byte[] body)
        {
            if (this.state == ProtocolState.closed)
            {
                return;
            }

            byte[] pkg = PackageProtocol.encode(type, body);

            transporter.send(pkg);
        }
Ejemplo n.º 16
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();
     }
 }
Ejemplo n.º 17
0
 internal void send(PackageType type, byte[] body)
 {
     if (this.state == ProtocolState.closed)
         return;
     this.transporter.send(PackageProtocol.encode(type, body));
 }