Windows 7上运行的Java应用程序如何选择要使用的网络适配器 [英] How can a java application running on windows 7 choose which network adapter to use

查看:169
本文介绍了Windows 7上运行的Java应用程序如何选择要使用的网络适配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在为运行Windows 7的设备(平板电脑)编写应用程序。
该应用程序是用Java编写的。
应用程序需要知道可用的网络适配器(WIFI,3G等)。
是否有一个类似于为android开发的java库android.net,android。 net.wifi等...-
简而言之,如何在Windows 7上运行的Java应用程序选择要使用的网络适配器?
谢谢!

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!

推荐答案

您可以使用 java.net.NetworkInterface.getNetworkInterfaces() 。注意:回送接口始终在此列表中。

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

但是,强制系统使用特定网络接口的唯一方法似乎是引用IP。地址打开特定的网络接口。例如, 4-arg Socket 构造函数将本地地址作为第三个参数(我只链接到一,其他将主机名作为第一个参数)。

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 具有 2-arg构造函数,其作用类似。

这篇关于Windows 7上运行的Java应用程序如何选择要使用的网络适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆