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 处理?