Пример #1
0
        public void HandleRecv(byte[] date, int length, uint timeNow)
        {
            this.kcp.Input(date, 0, length);
            this.GetService().AddToUpdate(this.Id);

            while (true)
            {
                int n = kcp.PeekSize();
                if (n == 0)
                {
                    this.OnError((int)SocketError.NetworkReset);
                    return;
                }
                this.packet.Stream.SetLength(ushort.MaxValue);
                int count = this.kcp.Recv(this.packet.Bytes, 0, ushort.MaxValue);
                if (count <= 0)
                {
                    return;
                }

                lastRecvTime = timeNow;

                this.packet.Flag   = this.packet.Bytes[0];
                this.packet.Opcode = BitConverter.ToUInt16(this.packet.Bytes, 1);
                this.packet.Stream.SetLength(count);
                this.packet.Stream.Seek(Packet.Index, SeekOrigin.Begin);
                this.OnRead(packet);
            }
        }
Пример #2
0
        public void HandleRecv(byte[] date, int length, uint timeNow)
        {
            this.kcp.Input(date, 0, length);
            this.GetService().AddToUpdate(this.Id);

            while (true)
            {
                int n = kcp.PeekSize();
                if (n == 0)
                {
                    this.OnError((int)SocketError.NetworkReset);
                    return;
                }
                int count = this.kcp.Recv(this.cacheBytes, 0, this.cacheBytes.Length);
                if (count <= 0)
                {
                    return;
                }

                lastRecvTime = timeNow;

                this.packet.Flag   = this.cacheBytes[0];
                this.packet.Opcode = BitConverter.ToUInt16(this.cacheBytes, 1);
                this.packet.Bytes  = this.cacheBytes;
                this.packet.Offset = Packet.Index;
                this.packet.Length = (ushort)(count - Packet.Index);
                this.OnRead(packet);
            }
        }