Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Client stay listen to port
Qt 6.11 is out! See what's new in the release blog

Client stay listen to port

Scheduled Pinned Locked Moved Solved Installation and Deployment
9 Posts 3 Posters 2.6k 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.
  • G Offline
    G Offline
    GianmarcoUtech
    wrote on last edited by
    #1

    I am developing an application that connects toserver with https requests written in c ++. I have sended data to the same server, using the QNetworkAccessManager and QNetworkRequest classes. I would like to use the same classes or subclasses of qnetworkto stay listening from server in a certain port, that is, I remian to listen until the server sends me a request. I can't use sockets because communication is based on https requests. Which strategy and which subclass should I use to listen on a particular port? Is it possible to use signal and slot? that is enter in slot when the server send me arequest. Can you post me a small example?
    I kindly ask you if you can answer me in a short time.

    Thanks for the support

    Pablo J. RoginaP 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      Hi and welcome to devnet,

      Can you explain how you are expecting your server to send you a request ?

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

      G 1 Reply Last reply
      0
      • G GianmarcoUtech

        I am developing an application that connects toserver with https requests written in c ++. I have sended data to the same server, using the QNetworkAccessManager and QNetworkRequest classes. I would like to use the same classes or subclasses of qnetworkto stay listening from server in a certain port, that is, I remian to listen until the server sends me a request. I can't use sockets because communication is based on https requests. Which strategy and which subclass should I use to listen on a particular port? Is it possible to use signal and slot? that is enter in slot when the server send me arequest. Can you post me a small example?
        I kindly ask you if you can answer me in a short time.

        Thanks for the support

        Pablo J. RoginaP Offline
        Pablo J. RoginaP Offline
        Pablo J. Rogina
        wrote on last edited by
        #3

        @GianmarcoUtech said in Client stay listen to port:

        I can't use sockets because communication is based on https requests

        Do you mean WebSockets? If so, you can use the WebSocket Secure (wss) protocol

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        G 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi and welcome to devnet,

          Can you explain how you are expecting your server to send you a request ?

          G Offline
          G Offline
          GianmarcoUtech
          wrote on last edited by
          #4

          Hi @SGaist,
          The server send me a request GET http in a determined url and port (example: http://123.2.3.1:80/). The body request http is customized from the server, for example :
          <body>
          "firtName" : "James",
          "secondName" : "Red"
          </body>

          1 Reply Last reply
          0
          • Pablo J. RoginaP Pablo J. Rogina

            @GianmarcoUtech said in Client stay listen to port:

            I can't use sockets because communication is based on https requests

            Do you mean WebSockets? If so, you can use the WebSocket Secure (wss) protocol

            G Offline
            G Offline
            GianmarcoUtech
            wrote on last edited by
            #5

            Hi @Pablo-J-Rogina,

            I can't use the socket because i receive from the server only request https. That is if i received a request GET from the server i must response direclty a this reuqst open from the server, so i can't open a new channel of the communication because the server already opened one. I hope I have clearly answered your question.

            Can you help me ?

            Pablo J. RoginaP 1 Reply Last reply
            0
            • G GianmarcoUtech

              Hi @Pablo-J-Rogina,

              I can't use the socket because i receive from the server only request https. That is if i received a request GET from the server i must response direclty a this reuqst open from the server, so i can't open a new channel of the communication because the server already opened one. I hope I have clearly answered your question.

              Can you help me ?

              Pablo J. RoginaP Offline
              Pablo J. RoginaP Offline
              Pablo J. Rogina
              wrote on last edited by
              #6

              @GianmarcoUtech said in Client stay listen to port:

              if i received a request GET from the server

              Usually, it's all the way around; that is, a client sends an HTTP(S) request (GET or POST for instance) to a server, which fulfills such request and provides a response back to the client.

              You may want to look at the Qt network examples , and also check additional documentation about client-server concepts.

              Upvote the answer(s) that helped you solve the issue
              Use "Topic Tools" button to mark your post as Solved
              Add screenshots via postimage.org
              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

              G 1 Reply Last reply
              1
              • Pablo J. RoginaP Pablo J. Rogina

                @GianmarcoUtech said in Client stay listen to port:

                if i received a request GET from the server

                Usually, it's all the way around; that is, a client sends an HTTP(S) request (GET or POST for instance) to a server, which fulfills such request and provides a response back to the client.

                You may want to look at the Qt network examples , and also check additional documentation about client-server concepts.

                G Offline
                G Offline
                GianmarcoUtech
                wrote on last edited by
                #7

                @Pablo-J-Rogina

                In my case the client has a double function, that is send requests and risponses at the server and in addition, it must stay to listen to the server. I can't develop this part, where i must remain in listen from server, that is wait that the server send me (at client) the requests https.

                I thought this solution:

                void remoteServer_ShortTest2::listen()
                {
                QNetworkAccessManager *managerLis = new QNetworkAccessManager(this);

                const QUrl url(QStringLiteral("http://187.138.169.1:8080"));
                QNetworkRequest request(url);
                
                connect(managerLis, SIGNAL(finished(QNetworkReply*)), this, SLOT(splitServerReq(QNetworkReply*)));
                

                }

                void remoteServer_ShortTest2::splitServerReq(QNetworkReply *reply)
                {
                // i client read request from the server
                }

                It's correct ?

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

                  No that is not how things are done.

                  QNetworkAccessManager is for client to server communication.

                  What you describe is that your application shall act as server as well as client just like your remote server shall act as client with your application.

                  That architecture is quiet strange. Why do you need such a strange two way communication setup ?
                  Why does your server need to act as client back to your application ?

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

                  G 1 Reply Last reply
                  1
                  • SGaistS SGaist

                    No that is not how things are done.

                    QNetworkAccessManager is for client to server communication.

                    What you describe is that your application shall act as server as well as client just like your remote server shall act as client with your application.

                    That architecture is quiet strange. Why do you need such a strange two way communication setup ?
                    Why does your server need to act as client back to your application ?

                    G Offline
                    G Offline
                    GianmarcoUtech
                    wrote on last edited by
                    #9

                    @SGaist ,

                    Thanks you, i resolved my problems using the class httpServer.

                    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