Networking code sometimes throws UnknownHostException

TCM picture TCM · May 25, 2010 · Viewed 7.1k times · Source

I am trying to data from a server. Sometimes my code fails due to an UnknownHostException. Why is that? What is the cause of this problem?

Answer

BalusC picture BalusC · May 25, 2010

This may occur if a hiccup in DNS server has occurred. Apart from making the DNS server more robust or looking for another one, you can also just use the full IP address instead of the hostname. This way it doesn't need to lookup the IP address based on the hostname. However, I would rather fix the DNS issue and prefer the DNS since IP addresses may change from time to time.