Beispiel #1
0
        protected void testReceiveMsg()
        {
            ClientBuffer pDataBuffer = new ClientBuffer();
            stAddBattleCardPropertyUserCmd pCmd = new stAddBattleCardPropertyUserCmd();

            for (int idx = 0; idx < 6; ++idx)
            {
                Ctx.m_instance.m_logSys.log(string.Format("接收缓冲区测试索引 {0}", idx));

                pDataBuffer.sendData.clear();
                pCmd.serialize(pDataBuffer.sendData);
                pDataBuffer.send();
                pDataBuffer.getSocketSendData();
                pDataBuffer.dynBuff.size = pDataBuffer.sendBuffer.length;
                Array.Copy(pDataBuffer.sendBuffer.dynBuff.buff, 0, pDataBuffer.dynBuff.buff, 0, pDataBuffer.sendBuffer.length);
                pDataBuffer.moveDyn2Raw();
                pDataBuffer.moveRaw2Msg();
            }

            Ctx.m_instance.m_logSys.log(string.Format("接收缓冲区测试索引 {0}", 6));

            stRetRemoveBattleCardUserCmd pCmd_1 = new stRetRemoveBattleCardUserCmd();

            pDataBuffer.sendData.clear();
            pCmd_1.serialize(pDataBuffer.sendData);
            pDataBuffer.send();
            pDataBuffer.getSocketSendData();
            pDataBuffer.dynBuff.size = pDataBuffer.sendBuffer.length;
            Array.Copy(pDataBuffer.sendBuffer.dynBuff.buff, 0, pDataBuffer.dynBuff.buff, 0, pDataBuffer.sendBuffer.length);
            pDataBuffer.moveDyn2Raw();
            pDataBuffer.moveRaw2Msg();

            for (int idx = 7; idx < 13; ++idx)
            {
                Ctx.m_instance.m_logSys.log(string.Format("接收缓冲区测试索引 {0}", idx));

                pDataBuffer.sendData.clear();
                pCmd.serialize(pDataBuffer.sendData);
                pDataBuffer.send();
                pDataBuffer.getSocketSendData();
                pDataBuffer.dynBuff.size = pDataBuffer.sendBuffer.length;
                Array.Copy(pDataBuffer.sendBuffer.dynBuff.buff, 0, pDataBuffer.dynBuff.buff, 0, pDataBuffer.sendBuffer.length);
                pDataBuffer.moveDyn2Raw();
                pDataBuffer.moveRaw2Msg();
            }

            Ctx.m_instance.m_netDispList.clearOneRevMsg();
            Ctx.m_instance.m_netDispList.clearOneHandleMsg();
        }
Beispiel #2
0
        protected void testMsgBuffer()
        {
            ClientBuffer pDataBuffer = new ClientBuffer();
            UnitTestStrCmd pUnitTestCmd = new UnitTestStrCmd();
            UnitTestNumCmd pUnitTesNumtCmd = new UnitTestNumCmd();

            // 发送第一个数据包
            pUnitTestCmd.testStr = "测试数据";
            pDataBuffer.sendData.clear();
            pUnitTestCmd.serialize(pDataBuffer.sendData);
            //pDataBuffer.sendData.position = 0;
            //pUnitTestCmd.derialize(pDataBuffer.sendData);
            pDataBuffer.send();

            // 发送第二个数据包
            pUnitTestCmd.testStr = "成功返回";
            pDataBuffer.sendData.clear();
            pUnitTestCmd.serialize(pDataBuffer.sendData);
            pDataBuffer.send();

            // 发送第三个数据包
            pUnitTesNumtCmd = new UnitTestNumCmd();
            pUnitTesNumtCmd.num = 2001;
            pDataBuffer.sendData.clear();
            pUnitTesNumtCmd.serialize(pDataBuffer.sendData);
            pDataBuffer.send();

            pDataBuffer.getSocketSendData();
            ByteBuffer cryptLenBA = new ByteBuffer();
            cryptLenBA.writeUnsignedInt32(pDataBuffer.sendBuffer.length);
            pDataBuffer.rawBuffer.circularBuffer.pushBackBA(cryptLenBA);                     // 自己补上消息头
            pDataBuffer.rawBuffer.circularBuffer.pushBackBA(pDataBuffer.sendBuffer);         // 直接放到接收原始消息缓冲区
            pDataBuffer.moveRaw2Msg();

            ByteBuffer bu;
            bu = pDataBuffer.getMsg();
            UAssert.DebugAssert(bu != null);
            pUnitTestCmd.derialize(bu);
            UAssert.DebugAssert(pUnitTestCmd.testStr.Substring(0, 4) == "测试数据");

            pDataBuffer.getSocketSendData();
            if (pDataBuffer.sendBuffer.length > 0)
            {
                cryptLenBA.clear();
                cryptLenBA.writeUnsignedInt32(pDataBuffer.sendBuffer.length);
                pDataBuffer.rawBuffer.circularBuffer.pushBackBA(cryptLenBA);                     // 自己补上消息头
                pDataBuffer.rawBuffer.circularBuffer.pushBackBA(pDataBuffer.sendBuffer);         // 直接放到接收原始消息缓冲区
                pDataBuffer.moveRaw2Msg();
            }

            bu = pDataBuffer.getMsg();
            UAssert.DebugAssert(bu != null);
            pUnitTestCmd.derialize(bu);
            UAssert.DebugAssert(pUnitTestCmd.testStr.Substring(0, 4) == "成功返回");

            pDataBuffer.getSocketSendData();
            if (pDataBuffer.sendBuffer.length > 0)
            {
                cryptLenBA.clear();
                cryptLenBA.writeUnsignedInt32(pDataBuffer.sendBuffer.length);
                pDataBuffer.rawBuffer.circularBuffer.pushBackBA(cryptLenBA);                     // 自己补上消息头
                pDataBuffer.rawBuffer.circularBuffer.pushBackBA(pDataBuffer.sendBuffer);         // 直接放到接收原始消息缓冲区
                pDataBuffer.moveRaw2Msg();
            }

            bu = pDataBuffer.getMsg();
            UAssert.DebugAssert(bu != null);
            pUnitTesNumtCmd.derialize(bu);
            UAssert.DebugAssert(pUnitTesNumtCmd.num == 2001);

            Ctx.m_instance.m_netDispList.clearOneRevMsg();
            Ctx.m_instance.m_netDispList.clearOneHandleMsg();
        }
Beispiel #3
0
        protected void testSend()
        {
            ClientBuffer pDataBuffer = new ClientBuffer();
            stUseObjectPropertyUserCmd pCmd = new stUseObjectPropertyUserCmd();

            for (int idx = 0; idx < 500; ++idx)
            {
                Ctx.m_instance.m_logSys.log(string.Format("发送缓冲区测试索引 {0}", idx));
                pDataBuffer.sendData.clear();
                pCmd.serialize(pDataBuffer.sendData);
                pDataBuffer.send();
            }
        }