TCP IP客户端读取接收数据c#


TcpClient client = new(SERVER_IP, PORT_NO);
NetworkStream stream = client.GetStream();
stream.Write(WriteArry, 0, WriteArry.Length);

byte[] data = new byte[10];

int recivedbyte = stream.Read(data, 0, 10);

如何检查接收到的数据长度是否小于10等待剩余数据?还是要接收多个数据?由于

byte[] data = new byte[10];
int read, remaining = data.Length;
while (remaining > 0 && (read =
stream.Read(data, data.Length - remaining, remaining)) > 0)
{
remaining -= read;
}
if (remaining != 0) throw new EndOfStreamException(); // EOF

最新更新