开发者

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

开发者 https://www.devze.com 2023-01-28 14:52 出处:网络
Hi I am writing an application for a device -- tablet -- running windows 7. The application is being written in java.

Hi I am writing an application for a device -- tablet -- running windows 7. The application is being written in java. The applicati开发者_运维百科on 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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消