Noelia Belen Lopez
Noelia Belen Lopez

Reputation: 126

UnresolvedAddressException socket channel

I'm trying to create a socket between my computer and a remote server but I'm getting an UnresolvedAddressException error when I do this :

    InetSocketAddress hostAddress = new InetSocketAddress("http://www.google.com", 80);
    SocketChannel serverChannel = SocketChannel.open(hostAddress);

Why is that?

Upvotes: 2

Views: 4687

Answers (1)

Youcef LAIDANI
Youcef LAIDANI

Reputation: 59988

You don't have to use http:// or https://, you just use:

InetSocketAddress hostAddress = new InetSocketAddress("www.google.com", 80);

Or you can use the IP address instead :

InetSocketAddress hostAddress = new InetSocketAddress("216.58.210.228", 80);

Upvotes: 6

Related Questions