client.ReceiveBufferSize没有给出正确的接收字节大小。
所以我尝试client.Client.SendFile("FileName.png")改用,但仍然给出相同的结果。我还检查了它发送的图像是否超过 64KB,并且确实显示它发送的图像超过了 64KB(从客户端)。
服务器代码:
TcpListener server = new TcpListener(IPAddress.Any,12345);
TcpClient client = server.AcceptTcpClient();
NetworkStream clientstream = client.GetStream();
byte[] ImageByte = new byte[client.ReceiveBufferSize];
int ReceiveCount = await clientstream.ReadAsync(ImageByte,0,ImageByte.Length);
File.WriteAllBytes("Screenshot.png",ImageByte);
客户代码:
TcpClient client = new TcpClient();
client.Connect(IPAddress.Parse("123.456.789.123"), 12345);
byte[] imagebyte = File.ReadAllBytes("ImageCaptured.temp");
client.GetStream().Write(imagebyte, 0, imagebyte.Length);
File.Delete("ImageCaptured.temp");
假设显示大约 128KB ,client.ReceiveBufferSize但最多只能显示 64KB。