Reputation: 1447
This is more of a novice question, but I am unable to get the type of answer I am looking for on Google.
I was reading the InetSocketAddress
class in java.net package and I came across this method named createUnresolved(String host, int port)
. This method creates an unresolved Socket.
Basically what do we mean by unresolved ? I have come across this term often in errors while compiling a program but never have understood it completely. Can anyone please explain the general meaning in java, and meaning with context to the said method.
Thanks.
Upvotes: 7
Views: 7601
Reputation: 25816
I had the same exception:
java.net.UnknownHostException: Host is unresolved: https://www.google.com
The problem was because I added the protocol https://
and resolved after I removed it.
try {
Socket socket = new Socket();
socket.connect(new InetSocketAddress("www.google.com", 443), 100);
socket.close();
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
Upvotes: -2
Reputation: 12484
I found this in a sun-blog:
But decided to keep it as is but use createUnresolved() to create an InetSocketAddress, so that we know what was used to instantiate it. If the user slapped in an IP address to begin with, we won't handle it. (I think it was indistinguishable before) The token will have whatever the user used (IP or name) in the beginning and in case of using name, the key to the token cache won't change even with addr changes. So the delegation token should continue to work.
Basically, it's a half-baked InetSocketAddress - so it's not the final iteration. It's an intermediary step..
And From API:
It can also be a pair (hostname + port number), in which case an attempt will be made to resolve the hostname.
If resolution fails then the address is said to be unresolved but can still be used on some circumstances like connecting through a proxy
So we didn't find the hostname, or the user-friendly "www.abc.com" method.
But if we are connecting via a proxy it's OK because that the proxy server handles the hostname .
Upvotes: 1