protected void ScanPackets()
    {
        while (m_recBufOffset > PACKAGE_HEADER_SIZE && !IsTerminateFlagSet())
        {
            ushort pkgSize = 0;
            if (BitConverter.IsLittleEndian)
            {
                pkgSize = BitConverter.ToUInt16(new byte[] { m_recBuf[1], m_recBuf[0] }, 0);
            }
            else
            {
                pkgSize = BitConverter.ToUInt16(new byte[] { m_recBuf[0], m_recBuf[1] }, 0);
            }
            Debug.Log("lucky pkg Size " + pkgSize + " " + m_recBufOffset);
            if (pkgSize <= m_recBufOffset)
            {
                byte[] _buffer = new byte[pkgSize - PACKAGE_HEADER_SIZE];
                Array.Copy(m_recBuf, PACKAGE_HEADER_SIZE, _buffer, 0, _buffer.Length);

                NetMsg tPackage = new NetMsg();

                ProtoUtil.BytesToJceStruct(_buffer, tPackage);

                DateTime next = firstTime.AddMilliseconds(tPackage.offset);

                Debug.Log("lucky tpackage time " + tPackage.offset);
                double sleeptime = (next - DateTime.Now).TotalMilliseconds;

                byte[] sendData = tPackage.buffer.ToArray();

                if (sleeptime < 0)
                {
                    stream.Write(sendData, 0, sendData.Length);
                }
                else
                {
                    Thread.Sleep((int)sleeptime);
                    stream.Write(sendData, 0, sendData.Length);
                }

                if (m_recBufOffset > pkgSize)
                {
                    for (int i = pkgSize, j = 0; i < m_recBufOffset; i++, j++)
                    {
                        m_recBuf[j] = m_recBuf[i];
                    }
                    m_recBufOffset -= pkgSize;
                }
                else
                {
                    m_recBufOffset = 0;
                }
            }
            else
            {
                break;
            }
        }
    }