所以我有这样的代码当获得计算机的IP就说明0.0.0.0
server = new ServerSocket(6789, 100);
showMessage("Your IP is: "+server.getInetAddress().getHostAddress()+"\n");
,我也试过.getInetAddress()。getCanonicalHostName()和其他一些人,他们都显示0.0.0.0或0.0.0.0/0.0.0.0。 任何人都知道为什么会发生这种情况? 此外,当客户端连接到正确的IP,它的工作原理,它只是显示错误。
好的,谢谢!但是,当我使用Inet4Address.getLocalHost()。getHostAddress()它使用我的Hamachi地址,那么如何将它指向某个适配器? – user3042719
如果您已经知道要使用的特定本地IP地址,则可以在ServerSocket构造函数中明确使用该IP地址。 – brak2718
@ user3042719某些操作系统的主机型号较弱,这意味着它们可以自由忽略要使用哪个适配器的提示。例如Linux系统使用弱主机模式。 http://en.wikipedia.org/wiki/Host_model –