O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

What just happened?

With QTcpServer::listen(), we defined that the server should listen to the localhost and the port 52693 for new incoming connections. The value used here, QHostAddress::LocalHost of the QHostAddress::SpecialAddress enumeration, will resolve to 127.0.0.1. Instead, if you pass QHostAddress::Any, the server will listen to all IPv4 interfaces as well as to IPv6 interfaces. If you only want to listen to a specific address, just pass this address as QHostAddress:

m_server->listen(QHostAddress("127.0.0.1"), 0); 

This will behave like the one in the preceding code, only in that the server will now listen to a port that will be chosen automatically. On success, listen() will return true. So, if something goes wrong in the example, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required