H2多网络接口
Posted
技术标签:
【中文标题】H2多网络接口【英文标题】:H2 multiple network interfaces 【发布时间】:2013-10-17 06:54:14 【问题描述】:H2 如何处理多个网络接口? 目前,我使用函数 getOwnIpAddress 禁用在一台计算机上拥有两个 ip,如果找到两个具有 IP 的接口,则会返回错误消息。
private String getOwnIpAddress()
ArrayList<String> ipAddresses = new ArrayList<>();
try
/*find out my own ip address*/
Enumeration<NetworkInterface> networkInterfaces;
networkInterfaces = NetworkInterface.getNetworkInterfaces();
for (NetworkInterface netint : Collections.list(networkInterfaces))
Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
for (InetAddress inetAddress : Collections.list(inetAddresses))
if (isIPAddress(inetAddress.getHostAddress())
&& !inetAddress.getHostAddress().equals("127.0.0.1"))
ipAddresses.add(inetAddress.getHostAddress());
if (ipAddresses.size() > 1)
DialogMessage.showMessage(null, Resource.getResourceString("tooManyInterfacesError"), "",
JOptionPane.ERROR_MESSAGE);
Main.quit();
else if (ipAddresses.size() > 0)
return ipAddresses.get(0);
else
return null;
catch (SocketException ex)
ex.printStackTrace();
return null;
我可以让 H2 选择一个 IP 吗?还是都可以在 auto_server 模式下由 H2 处理?
【问题讨论】:
我不确定这是否会有所帮助,但您是否尝试过系统属性h2.bindAddress
?另请参阅the javadocs。
【参考方案1】:
您可以使用系统属性h2.bindAddress
。
【讨论】:
在我的情况下,我会使用 h2.bindAddress="localhost" 因为我使用 auto_server 模式,以便特定的服务器 IP 对我的程序是透明的。然而,我无法理解 H2 在 LAN 和 Wan 接口的情况下会如何表现,H2 是否足够聪明以使用更快的 LAN 接口?我将对此进行测试,但有关该主题的一些官方文档或详细说明将非常有趣。谢谢以上是关于H2多网络接口的主要内容,如果未能解决你的问题,请参考以下文章