Important: Please read the Qt Code of Conduct -

Qt network, server, client, what is what in QT?

  • Hey

    I'm doing a "pre-study" of what I need to study when it comes to QT networking for my next test project.

    The target :
    Server - listens for incoming connections
    Client - connect to server
    Authentication - pw/user/etc
    PacketObject - a data objects send between client server.
    50k incoming/outgoing connections - ranging from as simple as login requests to as compelx as sending lots of data per request.

    For password hashing (?) I can use QPasswordDigestor

    For server I believe I need TcpServer. For the client I believe I need QNetworkAccessManager ?

    The general idea from past that I used was to start a server in a thread in while loop. Then have it constantly monitor for incoming connections, if connection was made, send a request for auth data, then receive it, check if valid and if so store in array the connection and keep it live until either side disconnects. If client dies, server will get disconnect call and clean up the task that client had assigned if any.

    When it comes to qt, TcpServer seems to just have listen() and that apparently just ... runs? So no need for making new thread, moving it to it and while loops? Hmm nice? :- )

    It also has newConnection signal. Does it mean that when I get newConnection I grab the connection (QTcpSocket), send request for pw and then, wait for reply somehow & check if reply is the auth I wanted and either store connection or deny connection? I take I would store the QTcpSocket in array then if its valid ? But that would be blocking, perhaps I should see if the connection is the auth, if not, send request for auth back to QNetworkAccessManager, which would then ask for authentication ? Not sure... the QNetworkAccessManager seems to have a lot of it built in, but where do I get a matching server to it ? Or we only have 50% of the classes and the rest we have to figure out by ourselves?

    Anyway, moving on, there seem to be a QNetworkRequest which seems to be equal to my understanding of a PacketObject - esentially its a message that lets say, starts with first 4bytes being an int, that definies its type, and then message being serialized data. So server can do something like ("Terrible sudo pseudocode") requestReceived(packetObject*patcket) (int)packet[0-4]==10{processAsX(packet} ? So instead of that I can relay on QNetworkRequest ? - somehow... :- )

    Not sure... For now I'm confused with:


    and how it all fits with QTcpServer...

    Any help would be great. I'm going over qt docs/examples but they feel a little random, each having some answers that I need but at the same time using different ways of communicating...


  • Lifetime Qt Champion


    Do you want your full implementation in Qt / C++ ? If so, then the Cutelyst project will likely be a very good base to work.

    You'll have all the basics in place without the need to re-implement everything yourself from scratch.

Log in to reply