Ejemplo n.º 1
0
        protected override bool DecodeReceive(byte[] buffer, int offset, int count, EndPoint endPoint, out int error)
        {
            error = 0;
            receiveBuffer.Copy(buffer, offset, count);

            int MESSAGE_LENGTH_SIZE = NetDefine.MESSAGE_LENGTH_SIZE;

            while (receiveBuffer.dataLength > MESSAGE_LENGTH_SIZE)
            {
                int contentLength = System.BitConverter.ToInt32(receiveBuffer.buffer, 0);

                if ((contentLength < 0) ||
                    (contentLength > NetDefine.MAX_MESSAGE_LENGTH) ||
                    (receiveBuffer.dataLength > NetDefine.MAX_MESSAGE_LENGTH))
                {
                    error = 1;
                    return(false);
                }

                if ((receiveBuffer.dataLength - MESSAGE_LENGTH_SIZE) >= contentLength)
                {
                    RawMessage message = RawMessage.Clone(receiveBuffer.buffer, MESSAGE_LENGTH_SIZE, contentLength);
                    OnReceiveAsyncCallback(message);
                    receiveBuffer.Clear(MESSAGE_LENGTH_SIZE + contentLength);
                }
                else
                {
                    return(true);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        public void Receive(byte[] buffer, int offset, int count)
        {
            RawMessage message = RawMessage.Clone(buffer, offset, count, NetDefine.MAX_KCP_MESSAGE_LENGTH);

            revQueue.Enqueue(message);
        }