UdpClient, Receive() right after Send() does not work?

那年仲夏 提交于 2019-12-01 17:49:40

问题


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?


回答1:


You probably want to setup two UdpClients: one for listening, one for sending.

For the receiving UdpClient, use the constructor that takes a port.




回答2:


probably the remote host has firewall then couldn't response to request, before send request set the

client.Client.ReceiveTimeout = 5000; 

so when the response couldn't get the request you have a exception



来源:https://stackoverflow.com/questions/221783/udpclient-receive-right-after-send-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!