/// <summary> /// 接收数据 /// </summary> /// <param name="data">数据</param> /// <param name="size">大小</param> /// <returns></returns> private bool ReceiveData(byte[] data, int size) { for (int i = 0; i < size; i++) { // IsEnd if ((0xEE == data[i]) && (0xEE == m_nRecvPrior)) { m_nRecvCount--; if (m_nRecvCount > 0) { m_Callee.OnSockReceive(this, m_RecvBuf, m_nRecvCount); } m_nRecvPrior = 0; m_nRecvCount = 0; continue; } else if ((0 == data[i]) && (0xEE == m_nRecvPrior)) { } else { if (m_nRecvCount < m_RecvBuf.Length) { m_RecvBuf[m_nRecvCount++] = data[i]; } else { //m_nRecvCount = 0; byte[] recvBuf = new byte[m_RecvBuf.Length + 1024]; Array.Copy(m_RecvBuf, recvBuf, m_RecvBuf.Length); m_RecvBuf = null; m_RecvBuf = recvBuf; m_RecvBuf[m_nRecvCount++] = data[i]; recvBuf = null; } } m_nRecvPrior = data[i]; } return(true); }
/// <summary> /// 接收数据 /// </summary> /// <param name="data">数据</param> /// <param name="size">大小</param> /// <returns></returns> private bool ReceiveData(byte[] data, int size) { for (int i = 0; i < size; i++) { // IsEnd if ((0xEE == data[i]) && (0xEE == m_nRecvPrior)) { m_nRecvCount--; if (m_nRecvCount > 0) { //解码 byte[] byteTemp = new byte[m_nRecvCount]; System.Array.Copy(m_RecvBuf, 0, byteTemp, 0, m_nRecvCount); if (MsgEncode.Instance.Ready) { MsgEncode.Instance.Decode(byteTemp, m_nRecvCount); } //m_Callee.OnSockReceive(this, m_RecvBuf, m_nRecvCount); m_Callee.OnSockReceive(this, byteTemp, m_nRecvCount); } m_nRecvPrior = 0; m_nRecvCount = 0; continue; } else if ((0 == data[i]) && (0xEE == m_nRecvPrior)) { } else { if (m_nRecvCount < m_RecvBuf.Length) { m_RecvBuf[m_nRecvCount++] = data[i]; } else { //m_nRecvCount = 0; byte[] mRecvBuf = new byte[m_RecvBuf.Length + 1000]; string info = string.Format(" - ReceiveData : Add Receive Buff Length ,Src = {0},Des = {1}", m_RecvBuf.Length, mRecvBuf.Length); Log.Trace(info); Array.Copy(m_RecvBuf, mRecvBuf, m_RecvBuf.Length); m_RecvBuf = mRecvBuf; m_RecvBuf[m_nRecvCount++] = data[i]; mRecvBuf = null; } } m_nRecvPrior = data[i]; } return(true); }