我正在通过com.sun.net.httpserver设置一个HttpServer。我希望能够通过我的公共ipv4地址访问服务器。
我已经设法让它和localhost一起工作了。
HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);
server.createContext("/", Main::server.setExecutor(null);
server.start();我试过了
InetAddress ip = InetAddress.getByName("83.180.65.342");
HttpServer server = HttpServer.create(new InetSocketAddress(ip, 8080), 0);但它会返回
java.ne.BindException: Cannot assign requested address: bind发布于 2019-05-08 18:55:15
您是否在本地开发计算机上执行此操作,而您的公共计算机实际上是另一台不同的计算机?这显然是行不通的。
如果这就是问题所在,请将您的IP地址设置为安装中的可配置属性,而不是对其进行硬编码。或者使用getLocalHost() (并正确配置机器的网络和DNS选项,使其不会返回127.0.0.1)。
https://stackoverflow.com/questions/56038623
复制相似问题