Example #1
0
        /// <summary>
        /// ReceiveData 从网络读取指定长度的数据
        /// </summary>
        public static byte[] ReceiveData(ESFramework.Server.Tcp.ISafeNetworkStream stream, int size)
        {
            byte[] result = new byte[size];

            NetHelper.ReceiveData(stream, result, 0, size);

            return(result);
        }
Example #2
0
        /// <summary>
        /// ReceiveData 从网络读取指定长度的数据 ,存放在buff中offset处
        /// </summary>
        public static void ReceiveData(ESFramework.Server.Tcp.ISafeNetworkStream stream, byte[] buff, int offset, int size)
        {
            int readCount  = 0;
            int totalCount = 0;
            int curOffset  = offset;

            while (totalCount < size)
            {
                int exceptSize = size - totalCount;
                readCount = stream.Read(buff, curOffset, exceptSize);
                if (readCount == 0)
                {
                    throw new IOException("NetworkStream Interruptted !");
                }
                curOffset  += readCount;
                totalCount += readCount;
            }
        }