我编写了简单的套接字,将特定请求发送到互联网服务器并接收响应,但是当发送的请求和套接字进入接收模式时,返回值的结果不完整,例如只有 25000 字节的 1075 字节接收时出现问题。
Socket skt = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
skt.Connect(hdr.Host, 80);
byte[] req_as_bytes = Encoding.UTF8.GetBytes(RequestParam);
SentLength = skt.Send(req_as_bytes);
skt.Send(Data, SocketFlags.None);
ReturnLength = skt.Receive(Data);
skt.Shutdown(SocketShutdown.Both);
skt.Close();
但是当我在 skt.recive() 数据像这段代码一样从服务器接收数据之前进入睡眠状态时
Socket skt = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
skt.Connect(hdr.Host, 80);
byte[] req_as_bytes = Encoding.UTF8.GetBytes(RequestParam);
SentLength = skt.Send(req_as_bytes);
skt.Send(Data, SocketFlags.None);
System.Threading.Thread.Sleep(4000);
ReturnLength = skt.Receive(Data);
skt.Shutdown(SocketShutdown.Both);
skt.Close();
解决这个问题的最佳解决方案是什么