Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 588
TimothyP Avatar asked Oct 21 '08 13:10

TimothyP


2 Answers

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

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

like image 186
ageektrapped Avatar answered Sep 30 '22 20:09

ageektrapped


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

like image 37
Mostafa Avatar answered Sep 30 '22 20:09

Mostafa