Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I select what Ethernet port I use for UDP communication?

I am writing code that will communicate to a network via UDP. From the udp documentation, all I have to do is specify a destination address and port and I can start sending/receiving data.

I have two separate Ethernet ports (and potentially a USB-to-RJ45 adapter) that I want to be able to communicate on. The documentation doesn't specify if there's a way to select what NIC card my data should be output on; is it possible to specify? My users will likely be connected to the Internet with their main Ethernet port, then using my code to do communication with the second port (or USB-to-RJ45). (These are two separate networks.)

like image 566
Dang Khoa Avatar asked Mar 23 '23 18:03

Dang Khoa


1 Answers

I think the interesting question here is, why you would ever want to choose which NIC to communicate through?

Unless I'm missing the point, your application should only specify which server (ip and port) to connect to, and the TCP/IP routing scheme of the OS should choose the proper NIC to use based on the target network.

like image 193
uhre Avatar answered Apr 13 '23 22:04

uhre