Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to make TCP client always wait for data in standby(?)
Forum Updated to NodeBB v4.3 + New Features

How to make TCP client always wait for data in standby(?)

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 404 Views 1 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.
  • K Offline
    K Offline
    kayakaan02
    wrote on 8 Dec 2022, 14:23 last edited by
    #1

    So I've been using to send commands and get data from a TCP server with this(https://doc.qt.io/qt-6/qtscxml-ftpclient-example.html) example of project.

    But I want to make this client always wait for new data so when data arrives it can re-use the it(I write it into a file) but to close when there is nothing to do.

    I wont send a command any other than USER, PORT, and PASS. I'll handle that from the server so I can send the dedicated file any time from server and update it for client's pc.

    Thanks in advance.

    J 1 Reply Last reply 8 Dec 2022, 14:26
    0
    • K Offline
      K Offline
      kayakaan02
      wrote on 8 Dec 2022, 19:13 last edited by
      #5

      So I found the quit mechanism is here at the example file:

      ftpClient.connectToState("B", QScxmlStateMachine::onEntry([&]() {
              if (commands.isEmpty()) {
                  app.quit();
                  return;
              }
              Command command = commands.takeFirst();
              qDebug() << "Posting command" << command.cmd << command.args;
              ftpClient.submitEvent(command.cmd, command.args);
          }));
      

      Here, if there is no command to send the app ends, I removed the app.quit() so it can wait.

      1 Reply Last reply
      0
      • K kayakaan02
        8 Dec 2022, 14:23

        So I've been using to send commands and get data from a TCP server with this(https://doc.qt.io/qt-6/qtscxml-ftpclient-example.html) example of project.

        But I want to make this client always wait for new data so when data arrives it can re-use the it(I write it into a file) but to close when there is nothing to do.

        I wont send a command any other than USER, PORT, and PASS. I'll handle that from the server so I can send the dedicated file any time from server and update it for client's pc.

        Thanks in advance.

        J Offline
        J Offline
        JonB
        wrote on 8 Dec 2022, 14:26 last edited by
        #2

        @kayakaan02 said in How to make TCP client always wait for data in standby(?):

        But I want to make this client always wait for new data

        Why? Why wait? The Qt way is to act on the data when it arrives via signal/slot.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kayakaan02
          wrote on 8 Dec 2022, 19:00 last edited by
          #3

          What I mean with wait is, the program ends when it's done with that signal so cannot act when data arrives the second time.

          So it should wait for the data without closing but I don't know how to do that.

          But after the program closes server still says it's connected?

          Maybe I make a second program in client project and after the connection is made, it just waits for the data without sending any commands?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 8 Dec 2022, 19:06 last edited by
            #4

            Hi,

            You should rather refactor the application so that it does what you want.

            There's no need for a second application. Don't quit when the transfer is done.

            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
            0
            • K Offline
              K Offline
              kayakaan02
              wrote on 8 Dec 2022, 19:13 last edited by
              #5

              So I found the quit mechanism is here at the example file:

              ftpClient.connectToState("B", QScxmlStateMachine::onEntry([&]() {
                      if (commands.isEmpty()) {
                          app.quit();
                          return;
                      }
                      Command command = commands.takeFirst();
                      qDebug() << "Posting command" << command.cmd << command.args;
                      ftpClient.submitEvent(command.cmd, command.args);
                  }));
              

              Here, if there is no command to send the app ends, I removed the app.quit() so it can wait.

              1 Reply Last reply
              0

              1/5

              8 Dec 2022, 14:23

              • Login

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