I want to create an InetSocketAddress but I want to do it right no matter if I get a host:port or a ip:port. I see it has two constructors, one for host (String) and another one for IP (InetAddress). Do I have to determine myself if I got an IP or HOST in order to choose between these two constructors? Am I missing something here?
Share
You can infer from the Javadoc, and see in the source code, that
new InetSocketAddress(String hostname, int port)callsInetAddress.getByName(hostname), which sorts all that out for you as documented.So the problem you’re posting about doesn’t really exist. Just pass whatever string you get, whether host name or IP address.