6

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?

TimothyP
  • 21,178
  • 26
  • 94
  • 142
  • 2
    Are you calling client.Connect()? If so, it will only accept data from the enpoint supplied in the Connect method. – Jon B Oct 21 '08 at 14:15
  • Did you ever solve this? – Alex Johnson Sep 13 '18 at 18:28
  • That was 10 years ago, as far as I can remember I went with @ageektrapped's solution and used to clients. These days I try to avoid using udp/tcp directly and prefer solutions like ZeroMQ/NetMQ combined with Protocol Buffers – TimothyP Sep 14 '18 at 02:05

2 Answers2

6

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

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

ageektrapped
  • 14,482
  • 7
  • 57
  • 72
1

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

CoolBeans
  • 20,654
  • 10
  • 86
  • 101
Mostafa
  • 11
  • 1