Boost :: asio - Clarification when binding to a specific network interface

I searched the web for answers, but I cannot find the complete answer.

Scenario: I have a client API and a server. The application uses the client API to communicate with the server. Both TCP and UDP are used for communication between the client API and the server. All this was written using ASIO.

The client API connects to the server via TCP, then sends commands through TCP and receives responses through TCP. The client API also listens on the UDP address, where it continuously receives data in real time.

The environment is a mixture of machines with WIN32 and WIN64. All machines also have 2 network cards.

Question: I would like to be able to "bind" my TCP and UDP connections to specific local network interfaces. I saw some information that discusses the socket option SO_BINDTODEVICE, as well as the bind function from earlier posts or other sites.

Is it possible to do this in a WIN32 / 64 environment? If you could shed some light on this, some examples or useful sites, I would really appreciate it.

Links I found:

+5
source share
1 answer

You can snap to a specific endpoint using the appropriate constructor tcp::ip::acceptor

include <boost/asio.hpp>

int
main()
{
    using namespace boost::asio;
    io_service service;
    ip::tcp::endpoint ep(
            ip::address::from_string( "127.0.0.1" ),
            1234
            );
    ip::tcp::acceptor acceptor( 
            service,
            ep
            );
}
+8

All Articles