开发者

QTcpServer retrieve more than one address

开发者 https://www.devze.com 2023-01-26 22:06 出处:网络
I use QTcpServer from the Qt-Framework with C++. I started it with ret = tcpServer->listen(QHostAddress::Any, 9871)

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?


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, specifying SIOCGIFSWADDR).


I agree with ereOn's answer above.

If you want to list your network interface adresses, take a look at QNetworkInterface.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号