UnresolvedAddressException 套接字通道
UnresolvedAddressException socket channel
我正在尝试在我的计算机和远程服务器之间创建一个套接字,但是在执行此操作时出现 UnresolvedAddressException
错误:
InetSocketAddress hostAddress = new InetSocketAddress("http://www.google.com", 80);
SocketChannel serverChannel = SocketChannel.open(hostAddress);
这是为什么?
您不必使用 http://
或 https://
,您只需使用:
InetSocketAddress hostAddress = new InetSocketAddress("www.google.com", 80);
或者您可以改用 IP 地址:
InetSocketAddress hostAddress = new InetSocketAddress("216.58.210.228", 80);
我正在尝试在我的计算机和远程服务器之间创建一个套接字,但是在执行此操作时出现 UnresolvedAddressException
错误:
InetSocketAddress hostAddress = new InetSocketAddress("http://www.google.com", 80);
SocketChannel serverChannel = SocketChannel.open(hostAddress);
这是为什么?
您不必使用 http://
或 https://
,您只需使用:
InetSocketAddress hostAddress = new InetSocketAddress("www.google.com", 80);
或者您可以改用 IP 地址:
InetSocketAddress hostAddress = new InetSocketAddress("216.58.210.228", 80);