QTcpServer 检索多个地址
我使用 C++ 的 Qt 框架中的 QTcpServer 。
我从
ret = tcpServer->listen(QHostAddress::Any, 9871)
With
QHostAddress serverAddress () const
Iretrieve the Address from it 开始。这是 0.0.0.0。在我看来,它应该监听多个地址(例如 127.0.0.1 和 LAN 地址)。
有没有一种方法可以从此类中检索多个地址?
I use QTcpServer from the Qt-Framework with C++.
I started it with
ret = tcpServer->listen(QHostAddress::Any, 9871)
With
QHostAddress serverAddress () const
I retrieve the Address from it. Which is 0.0.0.0. In my opinion it should listen on more than one address (like 127.0.0.1 and the LAN Address).
Is there a way to retrieve more than one address from this class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定您的问题到底是什么,但是...
通常,
0.0.0.0
意味着套接字侦听所有已启动并配置有有效的接口em> IPv4 地址。如果您想获取系统上所有可用的 IP 地址,您应该枚举网络接口,然后查询它们各自的 IPv4 地址(可能使用
ioctl
,指定SIOCGIFSWADDR
)。I'm not sure what your question is exactly, but...
Usually, a
0.0.0.0
means that the socket listen to all interfaces that are both up and configured with a valid IPv4 address.If you want to get all the available IP addresses on the system, you should enumerate the network interface then query their respective IPv4 address (Probably with an
ioctl
, specifyingSIOCGIFSWADDR
).我同意上面ereOn的回答。
如果您想列出网络接口地址,请查看QNetworkInterface。
I agree with ereOn's answer above.
If you want to list your network interface adresses, take a look at QNetworkInterface.