UdpClient, Receive () immediately after sending () does not work?

Consider the following code:

client.Send(data, data.Length, endpoint);
byte[] response = client.Receive(ref endpoint);

So far, according to WireShark (network sniffer), the remote host is responding with data, the application here is just waiting for data forever ... for some reason, it does not receive a response from the remote host.

Any ideas?

+3
source share
2 answers

You probably need to configure two UdpClients: one for listening, one for sending.

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

+5
source

perhaps the remote host has a firewall and then could not respond to the request before sending the request, set

client.Client.ReceiveTimeout = 5000; 

therefore, when the response could not receive the request, you have an exception

+1
source

Source: https://habr.com/ru/post/1698517/


All Articles