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

前端 未结 2 1588
甜味超标
甜味超标 2021-01-18 07:06

Consider the following code:

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

While, according to

相关标签:
2条回答
  • 2021-01-18 07:41

    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

    0 讨论(0)
  • 2021-01-18 07:47

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

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

    0 讨论(0)
提交回复
热议问题