我正在尝试在计算机和远程服务器之间创建套接字,但执行此操作时收到 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);
关于java - UnresolvedAddressException 套接字 channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44100661/