简体   繁体   English

Qt5在多宿主网络上绑定TCP套接字

[英]Qt5 Bind TCP Socket on Multihomed Network

I am having troubling using the new bind feature of the QTcpSocket class in Qt5. 我在使用Qt5中的QTcpSocket类的新绑定功能时遇到麻烦。 Any help figuring this out would be appreciated. 任何帮助弄清楚这一点将不胜感激。

I have a multihomed server that contains two NICs each with a separate IP address. 我有一台多宿主服务器,其中包含两个网卡,每个网卡都有一个单独的IP地址。 I have setup routing on the servers so that sending from the source address is sent out of the appropriate NIC regardless of the target remote address. 我在服务器上设置了路由,以便从源地址发送的数据都从适当的NIC发送出去,而不管目标远程地址如何。 That is, sending from xxx0 goes out over eth0 and xxx1 goes out over eth1 regardless of who the data is being sent to. 也就是说,无论将数据发送给谁,从xxx0发送的数据都将通过eth0发出,而xxx1将通过eth1的数据发出。 These NICs are connected via ethernet to long range Wifi links that are then connected to a switch. 这些NIC通过以太网连接到远程Wifi链接,然后将其连接到交换机。 These wifi links act as a transparent bridge and can rather be seen as two ethernet cables (but they are limited in bandwidth). 这些wifi链接充当透明的网桥,可以看作两条以太网电缆(但它们的带宽有限)。 The switch is then connected to a computer. 然后将交换机连接到计算机。 The goal is to transfer data between the server and the computer, and to use the two wifi links in parallel to increase bandwidth. 目标是在服务器和计算机之间传输数据,并并行使用两个wifi链接以增加带宽。 Although the server is physically a server, the software has the computer running as the software server (as others connect to it). 尽管服务器实际上是一台服务器,但是该软件具有作为软件服务器运行的计算机(其他计算机已连接到该服务器)。 That is, the physical server (software client) opens TCP sockets and attempts to connect to the listening computer (software server). 即,物理服务器(软件客户端)打开TCP套接字并尝试连接到侦听计算机(软件服务器)。

I use the bind feature of Qt5 to bind one TCP socket to the eth0 IP address and bind another TCP socket to the eth1 IP address. 我使用Qt5的绑定功能将一个TCP套接字绑定到eth0 IP地址,并将另一个TCP套接字绑定到eth1 IP地址。 I have verified this works with other programs like PING or file transfer via SCP. 我已经验证了它可以与其他程序(例如PING或通过SCP传输文件)一起使用。 See http://qt-project.org/doc/qt-5.0/qtnetwork/qabstractsocket.html#bind 参见http://qt-project.org/doc/qt-5.0/qtnetwork/qabstractsocket.html#bind

When I call bind the call succeeds and subsequent requests for the local IP address returns the correct value. 当我进行绑定时,调用成功,随后对本地IP地址的请求返回正确的值。 Eg socket->bind(ip) returns true and then socket->localAddress() equals ip. 例如,socket-> bind(ip)返回true,然后socket-> localAddress()等于ip。 However, when I call connectToHost the localAddress is lost when it starts the connection attempt and after connecting it has a different localAddress that is not the one I wanted it to have. 但是,当我调用connectToHost时,它在开始连接尝试时会丢失localAddress,并且在连接后它具有另一个不是我希望它拥有的localAddress。

Can anyone shed light into what is going on? 任何人都可以了解正在发生的事情吗? I am trying to avoid rewriting the software to reverse the roles of software client / server as these programs are quite big. 我试图避免重写软件来扭转软件客户端/服务器的角色,因为这些程序很大。 Thanks for the help. 谢谢您的帮助。

Qt项目错误跟踪器中有一个未解决的错误

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

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