0
H2如何處理多個網絡接口? 目前我禁用在一臺計算機上有兩個ips函數getOwnIpAddress,如果找到兩個具有IP的接口,它將返回一條錯誤消息。H2多個網絡接口
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'?另請參閱[javadocs](http://h2database.com/javadoc/org/h2/constant/SysProperties.html#h2.bindAddress)。 –