protected override int GetBodyLengthFromHeader(byte[] header, int offset, int length) { info.MessageNum= IntToByte.bytesToInt(header.CloneRange(offset, length),0); info.Messagelength = IntToByte.bytesToInt(header.CloneRange(offset, length), 4); info.MessageResNum = IntToByte.bytesToInt(header.CloneRange(offset, length), 8); return info.Messagelength; }
public List <ReceiveData> SendReceive(byte[] data) { List <ReceiveData> receiveData = new List <ReceiveData>(); Send(data); int count; byte[] reqdata = new byte[2048]; MemoryStream ms = new MemoryStream(); while (0 != (count = sc.Receive(reqdata))) { ms.Write(reqdata, 0, count); if (count != reqdata.Length) { break; } // if (count < 1024) break; } while (ms.Length > 0) { var datainfo = ms.ToArray(); int number = IntToByte.bytesToInt(datainfo, 0); //消息号 int length = IntToByte.bytesToInt(datainfo, 4); //消息长度 int resnumber = IntToByte.bytesToInt(datainfo, 8); //返回消息号 if (length > ms.Length) { break; } byte[] body = new byte[length]; Array.Copy(datainfo, 12, body, 0, length); receiveData.Add(new ReceiveData { Data = body, length = length, resnumber = resnumber, number = number }); ms = new MemoryStream(); if (datainfo.Length > length + 12) { ms.Write(datainfo, length + 12, datainfo.Length - length - 12); } } sc.Close(); return(receiveData); }