Beispiel #1
0
        private async void StartRecv()
        {
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            while (true)
            {
                if (this.Id == 0)
                {
                    return;
                }

                byte[] messageBytes;
                try
                {
                    if (this.isRpc)
                    {
                        this.isRpc = false;
                        await timerComponent.WaitAsync(0);
                    }
                    messageBytes = await channel.Recv();
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                    continue;
                }

                if (messageBytes.Length < 6)
                {
                    continue;
                }

                ushort opcode = BitConverter.ToUInt16(messageBytes, 0);

                try
                {
                    this.Run(opcode, messageBytes);
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                }
            }
        }
Beispiel #2
0
        private async void StartRecv()
        {
            while (true)
            {
                if (this.Id == 0)
                {
                    return;
                }

                byte[] messageBytes;
                try
                {
                    messageBytes = await channel.Recv();

                    if (this.Id == 0)
                    {
                        return;
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                    continue;
                }

                if (messageBytes.Length < 3)
                {
                    Log.Error($"message error length < 3, ip: {this.RemoteAddress}");
                    this.network.Remove(this.Id);
                    return;
                }

                ushort opcode = BitConverter.ToUInt16(messageBytes, 0);
                try
                {
                    this.Run(opcode, messageBytes);
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                }
            }
        }
Beispiel #3
0
        private async void StartRecv()
        {
            while (true)
            {
                if (this.Id == 0)
                {
                    return;
                }

                byte[] messageBytes;
                try
                {
                    messageBytes = await channel.Recv();

                    if (this.Id == 0)
                    {
                        return;
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                    continue;
                }

                if (messageBytes.Length < 3)
                {
                    continue;
                }

                ushort opcode = BitConverter.ToUInt16(messageBytes, 0);
                opcode = NetworkHelper.NetworkToHostOrder(opcode);
                try
                {
                    this.Run(opcode, messageBytes);
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                }
            }
        }
Beispiel #4
0
        private async void StartRecv()
        {
            while (true)
            {
                if (this.Id == 0)
                {
                    return;
                }

                byte[] rMessageBytes;
                try
                {
                    rMessageBytes = await mChannel.Recv();

                    if (this.Id == 0)
                    {
                        return;
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                    continue;
                }

                if (rMessageBytes.Length < 3)
                {
                    continue;
                }

                ushort nOpcode = BitConverter.ToUInt16(rMessageBytes, 0);
                try
                {
                    this.Run(nOpcode, rMessageBytes);
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                }
            }
        }