boost::asio - 关于绑定到特定网络接口的澄清

发布于 2024-09-16 08:13:13 字数 849 浏览 3 评论 0原文

我一直在网上寻找答案,但似乎找不到完整的答案。

场景:我有一个客户端 API 和一个服务器。应用程序使用客户端 API 与服务器通信。 TCP 和 UDP 都用于客户端 API 和服务器之间的通信。所有这些都是使用 ASIO 编写的。

客户端 API 通过 TCP 连接到服务器,然后通过 TCP 发送命令并通过 TCP 接收响应。客户端 API 还监听 UDP 地址,连续接收实时数据。

该环境是运行 WIN32 和 WIN64 的机器的混合。所有机器还有 2 个网卡。

问题:我希望能够将我的 TCP 和 UDP 连接“固定”到特定的本地网络接口。我已经看到一些讨论 SO_BINDTODEVICE 套接字选项以及来自早期帖子或其他站点的绑定函数的信息。

在WIN32/64环境下可以这样做吗?如果您能阐明这一点、一些示例或有帮助的网站,我将非常感激。

我找到的链接:

  1. 使用 Linux 、如何指定在哪个以太网接口上传输数据
  2. http://tuxology.net/2008/05/15/forcing-connections-through-a-specific-interface/

I've been searching the net for answers but I can't seem to find a complete answer.

Scenario: I have a client API and a server. An application uses the client API to talk to the server. Both TCP and UDP are used to communicate between the client API and the server. All of this has been written using ASIO.

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

The environment is a mix of machines running WIN32 and WIN64. All of the machines also have 2 network cards.

Question: I would like to be able to 'pin' my TCP and UDP connections to specific local network interfaces. I have seen some info that discusses the SO_BINDTODEVICE socket option as well as the bind function from earlier posts or other sites.

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

Links I've found:

  1. Using Linux, how to specify which ethernet interface data is transmitted on
  2. http://tuxology.net/2008/05/15/forcing-connections-through-a-specific-interface/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尐偏执 2024-09-23 08:13:13

您可以使用适当的 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
            );
}

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

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
            );
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文