Пример #1
0
        private bool RecvBytes(Socket tcp)
        {
            lock (bufferRecv)
            {
                byte[] buffer = bufferRecv;

                int received = tcp.Receive(buffer);
                //received = tcp.ReceiveAsync.Receive(buffer);

                byte[] bytesReceived = PackHelper.DecodeBytes(buffer, 1, received - 2);
                int    rightSize     = HeadPack.PackSize + ServerAnswerPack.PackSize + 1;
                if (bytesReceived.Length != rightSize)
                {
                    log.WarnFormat("返回消息长度不正确:" + bytesReceived.Length + "!=" + rightSize);
                }

                ServerAnswerPack pack = new ServerAnswerPack();
                RawFormatter.Instance.Bytes2Struct(pack, bytesReceived, HeadPack.PackSize, ServerAnswerPack.PackSize);

                if (pack.Result != 0)
                {
                    log.WarnFormat("发送失败:" + pack.Result.ToString());
                }
                if (waitReceive && receiveLogPrint)
                {
                    Console.WriteLine("SeqNO:{0} MessageId:{1} Result:{2}", pack.SeqNO, pack.MessageId, pack.Result);
                }
                return(pack.Result == 0);
            }
        }