Noe*_*pez 1 java sockets nio channel
UnresolvedAddressException
我正在尝试在我的计算机和远程服务器之间创建一个套接字,但执行此操作时出现错误:
InetSocketAddress hostAddress = new InetSocketAddress("http://www.google.com", 80);
SocketChannel serverChannel = SocketChannel.open(hostAddress);
Run Code Online (Sandbox Code Playgroud)
这是为什么?
您不必使用http://
or https://
,您只需使用:
InetSocketAddress hostAddress = new InetSocketAddress("www.google.com", 80);
Run Code Online (Sandbox Code Playgroud)
或者您可以使用 IP 地址代替:
InetSocketAddress hostAddress = new InetSocketAddress("216.58.210.228", 80);
Run Code Online (Sandbox Code Playgroud)