简体   繁体   English

如何同时使用2 lan适配器?

[英]How to use simultaneously 2 lan adapters?

I have following task, would you suggest, whether (and how if yes) it is possible to solve it: 我有以下任务,您是否建议(以及如何解决)有可能解决:

A computer has 2 LAN adapters; 一台计算机具有2个LAN适配器; each one is connected to different network provider. 每个都连接到不同的网络提供商。 Some information must be sent via first one and some information via second one. 一些信息必须通过第一个发送,而某些信息则通过第二个发送。

Is it possible somehow to specify which adapter to use by initialization of a connection? 是否可以通过连接初始化指定使用哪个适配器?

In Java you can use the NetworkInterface class, in conjunction with Socket.bind() to specify what interface to bind to. 在Java中,可以将NetworkInterface类与Socket.bind()结合使用以指定要绑定到的接口。

Example, taken from this reference : 示例,从此参考资料中获取

NetworkInterface nif = NetworkInterface.getByName("bge0");
Enumeration nifAddresses = nif.getInetAddresses();

Socket soc = new java.net.Socket();
soc.bind(nifAddresses.nextElement());
soc.connect(new InetSocketAddress(address, port));

Then by setting up two sockets, one per interface you can use both simultaneously. 然后,通过设置两个插槽,每个接口一个,您可以同时使用两个插槽。

The other way to solve this problem though is with interface bonding , which is a configuration issue (eg on Linux ) and presents two physical interfaces as one virtual interface. 解决该问题的另一种方法是使用接口绑定 ,这是一个配置问题(例如, 在Linux上 ),并且将两个物理接口表示为一个虚拟接口。 (Bonding is the exact opposite of specifying which interface to use when creating a socket, but isn't a programming issue though) (绑定与指定在创建套接字时使用哪个接口完全相反,但不是编程问题)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM