我试图弄清楚从 NetworkStream 读取时应该将 byteSize 设置为什么大小。使用较小或较大数字的优缺点是什么?
我看到很多例子都使用 256。为什么?
int byteSize = 256;
TcpListener server = new TcpListener(IPAddress.Any, 9999);
server.Start();
Byte[] bytes = new Byte[byteSize];
TcpClient client = server.AcceptTcpClient();
NetworkStream stream = client.GetStream();
int i = 0;
while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
// Do stuff with the stream
}