コード例 #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 == enPackageType.Handshake && this.state == enProtocolState.handshaking)
        {
            //Ignore all the message except handshading
            MessageObject data = (MessageObject)SimpleJson.SimpleJson.DeserializeObject(Encoding.UTF8.GetString(pkg.body));

            ProcessHandshakeData(data);

            this.state = enProtocolState.working;
        }
        else if (pkg.type == enPackageType.Heartbeat && this.state == enProtocolState.working)
        {
            this.heartBeatService.ResetTimeout();
        }
        else if (pkg.type == enPackageType.Data && this.state == enProtocolState.working)
        {
            this.heartBeatService.ResetTimeout();
            pomeloClient.ProcessMessage(messageProtocol.Decode(pkg.body));
        }
        else if (pkg.type == enPackageType.Kick)
        {
            this.GetPomeloClient().Disconnect();
            this.Close();
        }
    }