Matthieu Labour
Matthieu Labour

Reputation: 41

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

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!

Upvotes: 4

Views: 761

Answers (1)

Powerlord
Powerlord

Reputation: 88796

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.

Upvotes: 1

Related Questions