所以我沟通与机器通过局域网。
后设立的TcpClient,并发送机命令NetworkStream.write命令,将数据返回给我。流成功闭幕标志是(0XAA将0x55)尽管stream.read被卡在while循环语句和不退出它的所有数据包发送。通过wireshark的,我可以看到它发出的所有数据包后,机器保持在Wireshark流活着每两分钟。
我已尝试
- 退出循环时,它看到的是结束标志(0XAA将0x55)
- 机器发回包含整个数据包的大小和闭幕后,已经达到了3包
曾尝试多种方法后,没有运气在退出这个while语句。
任何想法。请注意这台机器从未发送-1我相信这是0xFFFFFF发送0XAA,并在2个字节作为结束标志的将0x55,但我不能得到这个循环
if (initialLength < 1)
{
initialLength = 32768;
}
byte[] buffer = new byte[initialLength];
int read = 0;
int chunk;
int buffSize = 500000;
while ((chunk = stream.Read(buffer, read, buffer.Length - read)) < buffSize)
{
read += chunk;
// If we've reached the end of our buffer, check to see if there's
// any more information
int interval = 0;
if (interval == 0)
{
byte[] aSize = new byte[3];
aSize[0] = buffer[2];
aSize[1] = buffer[3];
aSize[2] = buffer[4];
buffSize = ConvertByteArrayToInt(aSize);
}
if (read == buffer.Length)
{
int nextByte = stream.ReadByte();
// End of stream? If so, we're done
if (nextByte == -1)
{
return buffer;
}
// Nope. Resize the buffer, put in the byte we've just
// read, and continue
byte[] newBuffer = new byte[buffer.Length * 2];
Array.Copy(buffer, newBuffer, buffer.Length);
newBuffer[read] = (byte)nextByte;
buffer = newBuffer;
read++;
}
}
// Buffer is now too big. Shrink it.
byte[] ret = new byte[read];
Array.Copy(buffer, ret, read);
return ret;