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, ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.