bool RecvData(Socket socket, int recvSize) { int offset = 0; while (offset < recvSize) { uint recvID = System.BitConverter.ToUInt32(BUFF, offset); offset += 4; if (recvID == ConstValue.HEARBEAT_ID) //心跳 { // Debug.Log("recv hearbeat."); } else if (recvID == ConstValue.PING_ID) { //m_bSendPing = true; } else if (IS_ANSWER(recvID)) { recvID = RESET_ANSWER(recvID); if (recvID == m_SendID && m_SendBuff != null) { m_SendBuff = null; } } else { byte cmdCount = BUFF[offset++]; uint maxID = recvID + cmdCount; if (maxID > m_RecvID) { for (uint id = recvID; id < maxID; ++id) { ushort cmdSize = System.BitConverter.ToUInt16(BUFF, offset); if (cmdSize > recvSize - offset) { return(false); } ushort cmdType = System.BitConverter.ToUInt16(BUFF, offset + 2); if (id >= m_RecvID && cmdType != 0) { m_Handler.Handle(BUFF, (ushort)offset, (ushort)cmdSize); } offset += cmdSize; } m_RecvID = maxID; } m_bSendBackID = true; break; } } return(true); }
bool RecvData(byte[] buff) { while (m_RecvSize >= ClientSetting.CMD_MIN_SIZE) { uint recvID = System.BitConverter.ToUInt32(buff, m_Offset); if (recvID == ConstValue.HEARBEAT_ID) { m_Offset += 4; m_RecvSize -= 4; } else if (recvID == ConstValue.PING_ID) { m_Offset += 4; m_RecvSize -= 4; } else { ushort cmdSize = System.BitConverter.ToUInt16(buff, m_Offset); if (cmdSize > buff.Length) { return(false); } if (m_RecvSize >= cmdSize) { if (!m_Handler.Handle(buff, (ushort)m_Offset, (ushort)cmdSize)) { return(false); } m_Offset += cmdSize; m_RecvSize -= cmdSize; } else { break; } } } int freeBuffSize = buff.Length - (m_Offset + m_RecvSize); if (freeBuffSize < 128) { System.Array.Copy(buff, m_Offset, buff, 0, m_RecvSize); m_Offset = 0; } return(true); }
void RecvData(byte[] buff) { while (_mRecvSize >= ClientSetting.CMD_MIN_SIZE) { uint recvID = System.BitConverter.ToUInt32(buff, _mOffset); if (recvID == ConstValue.HEARBEAT_ID) { _mOffset += 4; _mRecvSize -= 4; } else if (recvID == ConstValue.PING_ID) { _mOffset += 4; _mRecvSize -= 4; } else { ushort cmdSize = System.BitConverter.ToUInt16(buff, _mOffset); if (cmdSize > buff.Length) { return; } if (_mRecvSize >= cmdSize) { if (!_mHandler.Handle(buff, (ushort)_mOffset, (ushort)cmdSize)) { return; } _mOffset += cmdSize; _mRecvSize -= cmdSize; } else { break; } } } int freeBuffSize = buff.Length - (_mOffset + _mRecvSize); if (freeBuffSize < 128) { System.Array.Copy(buff, _mOffset, buff, 0, _mRecvSize); _mOffset = 0; } return; }
bool RecvData(Socket socket, int recvSize) { int offset = 0; while (recvSize > 0) { uint recvID = System.BitConverter.ToUInt32(BUFF, offset); offset += 4; recvSize -= 4; if (recvID == ConstValue.HEARBEAT_ID || recvID == ConstValue.PING_ID) { //m_bSendPing = true; } else if (IS_ANSWER(recvID)) { recvID = RESET_ANSWER(recvID); if (recvID == m_SendID && m_SendBuff != null) { m_SendBuff = null; } } else { ushort cmdSize = System.BitConverter.ToUInt16(BUFF, offset); if (cmdSize > recvSize) { return(false); } if (recvID == m_RecvID + 1) { //对方第一次发送的命令 ++m_RecvID; m_Handler.Handle(BUFF, (ushort)offset, (ushort)cmdSize); } m_bSendBackID = true; recvSize -= cmdSize; offset += cmdSize; } } return(true); }
bool RecvData(Socket socket, int recvSize) { int offset = 0; while (recvSize > 0) { uint recvID = System.BitConverter.ToUInt32(_buff, offset); offset += 4; recvSize -= 4; if (recvID == ConstValue.HEARBEAT_ID || recvID == ConstValue.PING_ID) { //m_bSendPing = true; } else if (IS_ANSWER(recvID)) { recvID = RESET_ANSWER(recvID); if (recvID == _mSendId && _mSendBuff != null) { _mSendBuff = null; } } else { ushort cmdSize = System.BitConverter.ToUInt16(_buff, offset); if (cmdSize > recvSize) { return(false); } if (recvID == _mRecvId + 1) { //对方第一次发送的命令 ++_mRecvId; _mHandler.Handle(_buff, (ushort)offset, (ushort)cmdSize); } _mBSendBackId = true; recvSize -= cmdSize; offset += cmdSize; } } return(true); }