byte[] allContent = null;
int AllLength = 0;
int count = 0;
int length= 1024;
byte[] readBuff = new byte[length];
List<byte[]> readBuffList = new List<byte[]>();
while (true)
{
int r = this._clientSocket.Receive(readBuff, 0, length, SocketFlags.None);
if(r < = 0) break;
try
{
count += r;
byte[] curReciveContent = readBuff.Skip(0).Take(r).ToArray();
if (allLen == 0)
{
//数据位长度,在第四位
byte[] lenBytes = curReciveContent.Skip(4).Take(4).ToArray();
Array.Reverse(lenBytes);
allLen = BitConverter.ToInt32(lenBytes, 0);
}
if (count == allLen)
{
allContent = new byte[length];
int curIndex = 0;
for (int i = 0; i < readBuffList.Count; i++)
{
byte[] tempReadBuffs = readBuffList[i];
Array.Copy(tempReadBuffs, 0, allContent, curIndex, tempReadBuffs.Length);
curIndex += tempReadBuffs.Length;
}
break;
}
}
}