How can a java application running on windows 7 choose which network adapter to use

走远了吗. 提交于 2019-12-10 15:28:47

问题


Hi I am writing an application for a device -- tablet -- running windows 7. The application is being written in java. The application needs to be aware of which networking adapter is available (WIFI, 3G, etc ...) Is there a java library similar to the one developed for android -- android.net, android.net.wifi, etc ... -- In brief, How can a java application running on windows 7 choose which network adapter to use ? Thank you!


回答1:


You can see which Network Interfaces are available using java.net.NetworkInterface.getNetworkInterfaces(). Note: The loopback interface is always present in this list.

However, it appears that the only way to force the system to use particular network interfaces is by referring to the IP address a particular network interface is on. For example, the 4-arg Socket constructors take the local address as the third argument (I only linked to one, the other takes the hostname as the first argument).

DatagramSocket has a 2-arg constructor that does something similar.



来源:https://stackoverflow.com/questions/4327970/how-can-a-java-application-running-on-windows-7-choose-which-network-adapter-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!