我的 Groovy 应用程序正在发送一些 HTTP 请求并使用URL.getText(). 此应用程序部署到具有不同 IPv4 地址的 Ubuntu 服务器。
我现在想在不同的这些 IP 上运行应用程序的不同实例。(如何)我能做到这一点吗?
我的 Groovy 应用程序正在发送一些 HTTP 请求并使用URL.getText(). 此应用程序部署到具有不同 IPv4 地址的 Ubuntu 服务器。
我现在想在不同的这些 IP 上运行应用程序的不同实例。(如何)我能做到这一点吗?
具有不同 IPv4 地址的 Ubuntu 服务器
据我了解,在您的机器上配置了多个网络接口(在每个网络接口中,您的机器具有不同的地址)。
要为您指定网络接口,java.net.Socket可以使用以下代码:
NetworkInterface nif = NetworkInterface.getByName("eth0");
Enumeration<InetAddress> nifAddresses = nif.getInetAddresses();
Socket soc = new java.net.Socket();
soc.bind(new InetSocketAddress(nifAddresses.nextElement(), 0));
soc.connect(new InetSocketAddress(address, port));
本文中的更多详细信息http://docs.oracle.com/javase/tutorial/networking/nifs/definition.html