How to make TCP client always wait for data in standby(?)
-
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.
-
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. -
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.
@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.
-
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?
-
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.
-
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.