.net - How to get UdpClient to react to DNS updates -
I am using an UdpClient to send packets to a server. I am starting the UdpClient on the creation of my sender object, using (hostname, port) constructor. When created in this manner, the UdpClient resolves the hostname to an IP address. The postal code of the UdpClient object uses the IP address.
Unfortunately, if the DNS alias is used to indicate a different IP address through the DNS system, then this change is not reflected in my dispatcher object, it has been rebuilt.
What would be the best way to respond to DNS changes on my sender object times? Performance is very important. I can think of many solutions:
- Perform a DNS solution on each call (i.e. overload which host hostname parameter accepts) Actually it can be very fast due to the Windows DNS cache, I do not know
- Running on a timer thread to check a DNS Chair from time to time, if the DNS alias solves a different IP If this happens, then it will somehow use the new IP address to be the UdpClient update. However, I really do not want to lock the independent object on every call - as I said, performance is important.
Anyone got any experience doing this?
I will separate the address resolution from UdpClient .
- Use the cloud to
IPaddress(and store in local variables) - The parameterized constructor of
UdpClientUse > Li> -
UdpClient -
sendon theIPEndPointparameter. .
On a background thread:
- Check for every x seconds for the updated DNS
- local
IPEndPointVariables that you pass in yourUdpClient.Sendcall.
Every time you do this, there is no need to destroy your UdpClient . Also, there is no need to lock while updating IPEndPoint . The worse case is that you have been sent a dirty to an old address, but since you are not notified on the update It is done, you still have to send dirty.
Comments
Post a Comment