Ejemplo n.º 1
0
        public void ReceivePackage(int len, byte[] data)
        {
            byte[] finalData = data.SubArray(0, len);

            packetBuffer = packetBuffer.Concat(finalData);

            //标记是否有完整的包接收到
            bool hasCompletePacket = false;

            do
            {
                int packSize = GetDataLength(packetBuffer);
                if (packSize == 0)
                {
                    break;
                }

                hasCompletePacket = packetBuffer.Length >= packSize;

                if (hasCompletePacket)
                {
                    byte[] packBytes = ArrayEx.CutHeadByLength(ref packetBuffer, packSize);
                    packageList.Add(Package.PrasePackage(packBytes));
                }
            } while (hasCompletePacket);
        }
Ejemplo n.º 2
0
        public void ReceivePackage(int len, byte[] data)
        {
            byte[] finalData = data.SubArray(0, len);

            packetBuffer = packetBuffer.Concat(finalData);

            //标记是否有完整的包接收到
            bool hasCompletePacket = false;

            do
            {
                int packSize = GetDataLength(packetBuffer);
                if (packSize == 0)
                {
                    break;
                }
                hasCompletePacket = packetBuffer.Length >= packSize;

                if (hasCompletePacket)
                {
                    byte[] packBytes = ArrayEx.CutHeadByLength(ref packetBuffer, packSize);
                    handleQueue.AddAction((act) =>
                    {
                        NetPackageHandler.HandlePackage(server, Package.PrasePackage(packBytes), act);
                    });
                }
            } while (hasCompletePacket);
        }