Пример #1
0
        /// <summary>
        /// ReceiveProtocolStream
        /// </summary>
        /// <param name="state"></param>
        /// <param name="protocol"></param>
        /// <param name="sobj"></param>
        /// <returns></returns>
        public static IEnumerable <byte[]> ReceiveProtocolStream(SocketState state, CommunicateProtocol protocol, IHSSocket sobj)
        {
            if (protocol == null)
            {
                throw new Exception("Protocol should not be null.");
            }
            if (state == null)
            {
                throw new Exception("StateClient should not be null.");
            }
            if (sobj == null)
            {
                throw new Exception("client should not be null.");
            }

            int readIndex = 0;
            int fileLen   = protocol.Stream2Len;

            while (readIndex < fileLen)
            {
                int bufferLen = GlobalConfig.Protocol_Buffer_Len;
                int readLen   = fileLen - readIndex >= bufferLen ? bufferLen : fileLen - readIndex;
                var cache     = sobj.SyncBufferReceive(state, readLen);
                readIndex += cache.Length;
                yield return(cache);
            }
        }
Пример #2
0
 /// <summary>
 /// ReceiveBytes
 /// </summary>
 /// <param name="state"></param>
 /// <param name="length"></param>
 /// <param name="sobj"></param>
 /// <returns></returns>
 public static byte[] ReceiveBytes(SocketState state, int length, IHSSocket sobj)
 {
     return(sobj.SyncBufferReceive(state, length));
 }