Send() 之后的 UdpClient、Receive() 不起作用?
考虑以下代码:
client.Send(data, data.Length, endpoint);
byte[] response = client.Receive(ref endpoint);
虽然根据 WireShark(网络嗅探器),远程主机确实回复了数据, 这里的应用程序只是永远等待数据......由于某种原因它没有收到来自远程主机的答案。
有任何想法吗?
Consider the following code:
client.Send(data, data.Length, endpoint);
byte[] response = client.Receive(ref endpoint);
While, according to WireShark (network sniffer), the remote host does reply with data,
the application here just waits for data forever... it does not receive the answer from the remote host for some reason.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能想要设置两个 UdpClient:一个用于监听,一个用于发送。
对于接收 UdpClient,使用采用端口的构造函数。
You probably want to setup two UdpClients: one for listening, one for sending.
For the receiving UdpClient, use the constructor that takes a port.
可能远程主机有防火墙,然后无法响应请求,在发送请求之前设置,因此
当响应无法获取请求时,您会遇到异常
probably the remote host has firewall then couldn't response to request, before send request set the
so when the response couldn't get the request you have a exception