Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Extending networking/socket programming functionality of a qml project
Forum Updated to NodeBB v4.3 + New Features

Extending networking/socket programming functionality of a qml project

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
92 Posts 5 Posters 21.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qcoderpro
    wrote on last edited by
    #35

    Can't anyone help me how to work the main issue out, please?
    I believe the main issue is how to set the IP address of the server app on the noip website or my hostname to make it possible for the client app to get access to the server app and establish a connection.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #36

      The main issue is that you currently do not understand properly how networking works.

      As already written, your device automatically gets an IP address as soon as it is properly connected to a network be it WiFi, 4G/5G etc.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Q 1 Reply Last reply
      0
      • SGaistS SGaist

        The main issue is that you currently do not understand properly how networking works.

        As already written, your device automatically gets an IP address as soon as it is properly connected to a network be it WiFi, 4G/5G etc.

        Q Offline
        Q Offline
        qcoderpro
        wrote on last edited by
        #37

        @SGaist

        I understand this. Suppose the server app is running on a device with IP: 123.456.789
        To give that address to the client app, you suggested noip. OK, I signed up and added a hostname too and posted my last talk with them above. Now the main issue is giving that address to the client app or as you say: updating a record on noip. How to do that? This is my problem.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #38

          The client uses the host name that's all from its side.

          You server needs to implement the client part that updates the noip record. Take a look at their client to implement that.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          Q 1 Reply Last reply
          1
          • SGaistS SGaist

            The client uses the host name that's all from its side.

            You server needs to implement the client part that updates the noip record. Take a look at their client to implement that.

            Q Offline
            Q Offline
            qcoderpro
            wrote on last edited by
            #39

            @SGaist

            The client uses the host name that's all from its side.

            The client connects to the hostname and gets its IP address. The IP of the hostname (I mean the one I added, "..dev.ddns.net") for example, is, 123.456.789, so the client now owns this address. Right?

            You server needs to implement the client part that updates the noip record.

            Does this mean that the server also needs to connect to the hostname above and gets that IP address!?

            Take a look at their client to implement that.

            Could you give me the address of that part, please?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #40

              No, the server has the address the client application is interested in. It does not get it from noip. noip is a DNS service that associates a hostname with an IP address, nothing more.

              As for writing code, see their documentation about that matter.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              Q 1 Reply Last reply
              1
              • SGaistS SGaist

                No, the server has the address the client application is interested in. It does not get it from noip. noip is a DNS service that associates a hostname with an IP address, nothing more.

                As for writing code, see their documentation about that matter.

                Q Offline
                Q Offline
                qcoderpro
                wrote on last edited by
                #41

                @SGaist
                Before writing the code, please let me understand the case completely.
                The server has an IP address that the client is interested in (for establishing the connection). So how the client can know of that IP address?
                The client can connect to hostname at noip and get the address of that hostname. But it's different from the server's IP! The server somehow should deliver its IP to the client for the connection. How is it done?

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #42

                  The client just uses the hostname. That's all.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  Q 1 Reply Last reply
                  1
                  • SGaistS SGaist

                    The client just uses the hostname. That's all.

                    Q Offline
                    Q Offline
                    qcoderpro
                    wrote on last edited by
                    #43

                    @SGaist

                    1. So to sum it up: The client connects to my hostname which has been updated by the server to show its IP address and since this way the client can see the server's IP address it can connect to it. Right?
                    2. If the above question is right, is this page the one I should study on how to make the server app update the hostname's record with its IP?
                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #44
                      1. Yes
                      2. Looks like it yes.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      Q 1 Reply Last reply
                      1
                      • SGaistS SGaist
                        1. Yes
                        2. Looks like it yes.
                        Q Offline
                        Q Offline
                        qcoderpro
                        wrote on last edited by
                        #45

                        @SGaist

                        So in my server app there should be a line of code as an HTTP request, like this example (of that page):
                        http://username:password@dynupdate.no-ip.com/nic/update?hostname=mytest.example.com&myip=192.0.2.25

                        So if:
                        my username at noip is: coderdevqt@gmail.com
                        my password there is: passwordexample
                        and my hostname there is: coderdev.ddns.net

                        that HTTP request should be:
                        coderdevqt@gmail.com:passwordexample@dynupdate.no-ip.com/nic/update?hostname=coderdev.ddns.net
                        Right?

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #46

                          Don't you think it would have been faster to just write and test the query ?

                          Also: https.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          Q 1 Reply Last reply
                          2
                          • SGaistS SGaist

                            Don't you think it would have been faster to just write and test the query ?

                            Also: https.

                            Q Offline
                            Q Offline
                            qcoderpro
                            wrote on last edited by qcoderpro
                            #47

                            @SGaist

                            I'm not sure how to make an HTTP request using QNetworkAccessManager by a single string. I tired this but neither of the qInfo() prints anything. The program also terminates at once! :|

                             QNetworkAccessManager* manager = new QNetworkAccessManager(this);
                                const QNetworkRequest request;
                                const QByteArray data {"https://coderdevqt@gmail.com:passwordexample@dynupdate.no-ip.com/nic/update?hostname=coderdev.ddns.net"};
                                manager->put(request,data);
                            
                                connect(manager, &QNetworkAccessManager::finished, [] {
                                    QNetworkReply* reply = nullptr;
                                    if(reply->error())
                                        qInfo() << "ERROR!: " + reply->errorString();
                                    else
                                        qInfo() << "Reply got back with no error!";
                            
                                    reply->deleteLater();
                                });
                            
                            SGaistS JonBJ 2 Replies Last reply
                            0
                            • Q qcoderpro

                              @SGaist

                              I'm not sure how to make an HTTP request using QNetworkAccessManager by a single string. I tired this but neither of the qInfo() prints anything. The program also terminates at once! :|

                               QNetworkAccessManager* manager = new QNetworkAccessManager(this);
                                  const QNetworkRequest request;
                                  const QByteArray data {"https://coderdevqt@gmail.com:passwordexample@dynupdate.no-ip.com/nic/update?hostname=coderdev.ddns.net"};
                                  manager->put(request,data);
                              
                                  connect(manager, &QNetworkAccessManager::finished, [] {
                                      QNetworkReply* reply = nullptr;
                                      if(reply->error())
                                          qInfo() << "ERROR!: " + reply->errorString();
                                      else
                                          qInfo() << "Reply got back with no error!";
                              
                                      reply->deleteLater();
                                  });
                              
                              SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #48

                              @qcoderpro said in Extending networking/socket programming functionality of a qml project:

                              connect(manager, &QNetworkAccessManager::finished, [] {
                              QNetworkReply* reply = nullptr;
                              if(reply->error())

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              2
                              • Q qcoderpro

                                @SGaist

                                I'm not sure how to make an HTTP request using QNetworkAccessManager by a single string. I tired this but neither of the qInfo() prints anything. The program also terminates at once! :|

                                 QNetworkAccessManager* manager = new QNetworkAccessManager(this);
                                    const QNetworkRequest request;
                                    const QByteArray data {"https://coderdevqt@gmail.com:passwordexample@dynupdate.no-ip.com/nic/update?hostname=coderdev.ddns.net"};
                                    manager->put(request,data);
                                
                                    connect(manager, &QNetworkAccessManager::finished, [] {
                                        QNetworkReply* reply = nullptr;
                                        if(reply->error())
                                            qInfo() << "ERROR!: " + reply->errorString();
                                        else
                                            qInfo() << "Reply got back with no error!";
                                
                                        reply->deleteLater();
                                    });
                                
                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by
                                #49

                                @qcoderpro
                                I would also suggest you do the connect(manager, ...) before manager->put() not afterwards.

                                1 Reply Last reply
                                0
                                • Q Offline
                                  Q Offline
                                  qcoderpro
                                  wrote on last edited by qcoderpro
                                  #50

                                  @SGaist
                                  What do you mean by copying part of the code I wrote above? I didn't get it. Do you mean those three lines of code are sufficient to make an Http request? Then how about the string!? :|

                                  @JonB
                                  You mean this way?

                                  QNetworkAccessManager* manager = new QNetworkAccessManager(this);
                                  const QNetworkRequest request;
                                  const QByteArray data {"https://coderdevqt@gmail.com:passwordexample@dynupdate.no-ip.com/nic/update?hostname=coderdev.ddns.net"};
                                  
                                  connect(manager, &QNetworkAccessManager::finished, [] {
                                          QNetworkReply* reply = nullptr;
                                          if(reply->error())
                                              qInfo() << "ERROR!: " + reply->errorString();
                                          else
                                              qInfo() << "Reply got back with no error!";
                                  
                                          reply->deleteLater();
                                      });
                                  
                                  manager->put(request,data);
                                  

                                  I'm confused! :(
                                  Furthermore the put function uploads the contents of data to the destination request, while both my data and destination are packed into that data!

                                  JonBJ 1 Reply Last reply
                                  0
                                  • Q qcoderpro

                                    @SGaist
                                    What do you mean by copying part of the code I wrote above? I didn't get it. Do you mean those three lines of code are sufficient to make an Http request? Then how about the string!? :|

                                    @JonB
                                    You mean this way?

                                    QNetworkAccessManager* manager = new QNetworkAccessManager(this);
                                    const QNetworkRequest request;
                                    const QByteArray data {"https://coderdevqt@gmail.com:passwordexample@dynupdate.no-ip.com/nic/update?hostname=coderdev.ddns.net"};
                                    
                                    connect(manager, &QNetworkAccessManager::finished, [] {
                                            QNetworkReply* reply = nullptr;
                                            if(reply->error())
                                                qInfo() << "ERROR!: " + reply->errorString();
                                            else
                                                qInfo() << "Reply got back with no error!";
                                    
                                            reply->deleteLater();
                                        });
                                    
                                    manager->put(request,data);
                                    

                                    I'm confused! :(
                                    Furthermore the put function uploads the contents of data to the destination request, while both my data and destination are packed into that data!

                                    JonBJ Offline
                                    JonBJ Offline
                                    JonB
                                    wrote on last edited by
                                    #51

                                    @qcoderpro said in Extending networking/socket programming functionality of a qml project:

                                    @JonB
                                    You mean this way?

                                    Yes, I think it's preferable to attach the slot to manager's signal before you call manager->put(). Though @VRonin pointed out it doesn't actually matter in this case, but it's good style anyway.

                                    1 Reply Last reply
                                    0
                                    • VRoninV Offline
                                      VRoninV Offline
                                      VRonin
                                      wrote on last edited by VRonin
                                      #52

                                      Since I've been summoned... how is this not a segfault?

                                      QNetworkReply* reply = nullptr;
                                      if(reply->error())
                                      

                                      What you should do is connect the QNetworkReply, not the QNetworkAccessManager.

                                      // the initialisation of these 2 looks wrong but I'll ignore it for now
                                      QNetworkAccessManager* manager = new QNetworkAccessManager(this);
                                      const QNetworkRequest request;
                                      const QByteArray data {"https://coderdevqt@gmail.com:passwordexample@dynupdate.no-ip.com/nic/update?hostname=coderdev.ddns.net"};
                                      QNetworkReply* reply = manager->put(request,data);
                                      connect(reply,&QNetworkReply::finished,this,[reply](){
                                          if(reply->error())
                                              qInfo() << "ERROR!: " + reply->errorString();
                                          else
                                              qInfo() << "Reply got back with no error!";
                                      });
                                      connect(reply,&QNetworkReply::finished,reply,&QNetworkReply::deleteLater);
                                      

                                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                      ~Napoleon Bonaparte

                                      On a crusade to banish setIndexWidget() from the holy land of Qt

                                      Q 1 Reply Last reply
                                      2
                                      • VRoninV VRonin

                                        Since I've been summoned... how is this not a segfault?

                                        QNetworkReply* reply = nullptr;
                                        if(reply->error())
                                        

                                        What you should do is connect the QNetworkReply, not the QNetworkAccessManager.

                                        // the initialisation of these 2 looks wrong but I'll ignore it for now
                                        QNetworkAccessManager* manager = new QNetworkAccessManager(this);
                                        const QNetworkRequest request;
                                        const QByteArray data {"https://coderdevqt@gmail.com:passwordexample@dynupdate.no-ip.com/nic/update?hostname=coderdev.ddns.net"};
                                        QNetworkReply* reply = manager->put(request,data);
                                        connect(reply,&QNetworkReply::finished,this,[reply](){
                                            if(reply->error())
                                                qInfo() << "ERROR!: " + reply->errorString();
                                            else
                                                qInfo() << "Reply got back with no error!";
                                        });
                                        connect(reply,&QNetworkReply::finished,reply,&QNetworkReply::deleteLater);
                                        
                                        Q Offline
                                        Q Offline
                                        qcoderpro
                                        wrote on last edited by
                                        #53

                                        @VRonin

                                        That's better, thanks. The project doesn't itself terminate and works but I get this error!
                                        fdgdfg.PNG
                                        I've used the exact same string as yours, of course with my real info.

                                        1 Reply Last reply
                                        0
                                        • VRoninV Offline
                                          VRoninV Offline
                                          VRonin
                                          wrote on last edited by
                                          #54

                                          @qcoderpro said in Extending networking/socket programming functionality of a qml project:

                                          I've used the exact same string as yours, of course with my real info.

                                          Yeah, I expected something like that, hence my comment:

                                          the initialisation of these 2 looks wrong but I'll ignore it for now

                                          Your request has no url...
                                          I have no idea how the server you are trying to connect to works so it's hard to tell you exactly what to do. Did you manage to do what you want with the server with another tool (like curl, or a browser-based rest client)?

                                          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                          ~Napoleon Bonaparte

                                          On a crusade to banish setIndexWidget() from the holy land of Qt

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved