Reputation: 41266
I am using a UdpClient to send packets to a server. I am initializing the UdpClient upon construction of my Sender object, using the (hostname, port) constructor. When constructed in this manner, the UdpClient resolves the hostname to an IP address. Subsequent calls to the UdpClient object use the IP address.
Unfortunately, if the DNS alias used is updated through the DNS system to point to a different IP address, this change is not reflected in my Sender object unless it is re-created.
What would be the best way to have my Sender object react to DNS changes in a timely manner? Performance is very important. I can think of several solutions:
Anybody got any experience of doing this?
Upvotes: 0
Views: 608
Reputation: 10038
I would separate the address resolution from the UdpClient
.
Dns
class to resolve IPaddress
(and store in local variable)UdpClient
, UdpClient
Send
with the IPEndPoint
parameter.On a background thread:
IPEndPoint
variable you pass to your UdpClient.Send
call.No need to destroy your UdpClient
every time you do this.
Also, no need to lock when updating the IPEndPoint
. The worse case is that you have one dirty send to an old address, but since you are not instantly notified on updates, you will have dirty sends anyway.
Upvotes: 2