即使服务器 确实回复,因为服务器速度不够,有时候recByte
将无法收到响应。如果发生了,我使用如何改进这个TCP代码?
catch (System.IO.IOException ioe)
为了防止错误,但有没有可能的替代方案,允许客户端等待一会儿? 我也尝试
clientStream.ReadTimeout = 20000;
,但它没有工作
TcpClient Client = new TcpClient();
Client.Connect(ipaddress, portnum);
NetworkStream clientStream = Client.GetStream();
byte[] buffer = themessagetosent;
clientStream.Write(buffer, 0, buffer.Length);
byte[] recByte = theresponse;
clientStream.Read(recByte, 0, recByte.Length);
增加ReceiveTimeOut似乎没有帮助,看起来程序不知道如何接收延迟的消息错误是System.Net.Sockets.SocketException:连接尝试失败,因为连接方在一段时间后没有正确响应,或建立的连接失败,因为连接的主机未能响应@AlexAza – Corbee 2011-06-01 02:42:39
什么是SocketErrorCode的值? – 2011-06-01 02:50:02
WSAETIMEDOUT 10060 @AlexAza – Corbee 2011-06-01 03:46:07