Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Remote Objects: Can't register Clients to Registry using a TCP-connection



  • So lately I have been trying out the functionalities of the Qt remoteobjects and wanted to establish a TCP connection between a Host Node and Client Nodes using a Registry for the Clients to register at the Host Node.
    I therefore used the code provided in the official external schemas documentation: https://doc.qt.io/qt-5/qtremoteobjects-external-schemas.html and additionally enabled the remoting of the host node on the server side while I wanted to aquire the Replica object on the client side.
    My Server Side Code:

        FileManager fileManager;
    
        const QUrl registryUrl = QUrl(QStringLiteral("tcp://serverIpAdressHere:65212"));
        const QUrl extUrl = QUrl(QStringLiteral("exttcp://serverIpAdressHere:65213"));
    
        QTcpServer tcpServer;
        tcpServer.listen(QHostAddress(extUrl.host()), extUrl.port());
    
        QRemoteObjectRegistryHost registry(registryUrl);
    
        QRemoteObjectHost srcNode(extUrl, registryUrl, 
    QRemoteObjectHost::AllowExternalRegistration);
        srcNode.enableRemoting(&fileManager);
    
    //Do work with fileManager
    

    My Client Side Code:

        const QUrl registryUrl = QUrl(QStringLiteral("tcp://serverIpAdressHere:65212"));
    
        QRemoteObjectNode repNode(registryUrl);
    
        QRemoteObjectNode::RemoteObjectSchemaHandler setupTcp = [&repNode](QUrl url) -> void {
            QTcpSocket *socket = new QTcpSocket(&repNode);
            QObject::connect(socket, &QTcpSocket::connected,
                    [socket, &repNode]() -> void {
                qDebug() << "Added client side connection";
                repNode.addClientSideConnection(socket);
            });
            QObject::connect(socket, QOverload<QAbstractSocket::SocketError>::of(&QSslSocket::error),
                    [socket](QAbstractSocket::SocketError) -> void {
                qDebug() << "Deleted socket";
                delete socket;
            });
            qDebug() << "Connected to host with URL: " << url.host() <<":" << url.port();
            socket->connectToHost(url.host(), url.port());
        };
    
        repNode.registerExternalSchema(QStringLiteral("exttcp"), setupTcp);
    
       QSharedPointer<QRemoteObjectReplica> ptr;
       ptr.reset(repNode.acquire<FileManagerReplica>());
       Client client(ptr);
    
    //Do work with client
    

    I created a .rep file for my FileManager class which simply sends some signals with file contents to the Client and wanted to connect each Client process to the corresponding Registry using the registryUrl.

    Now my problem is that the TCP-connection seems to be established normally since the server side code approves a correct connection of the client to the provided QTcpServer (QTcpServer::newConnection() gets emitted), however the Client doesn't receive any of the file contents being provided to him using remoteobjects. Please note that the communication between the processes works fine with URLs using the local schema and therefore not using TCP. So the problem must appear in the actual registration of the clients to the registry using external schemas.
    Does anyone see a problem with my code? Can't really figure out the problem since the way the TCP connection is established is the same as described in the documentation.

    Thank you very much!