Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The async_publish_time.cpp code has a bug: the connection is closed before starting to publish timestamp messages #528

Open
brocoli12138 opened this issue Jan 1, 2025 · 2 comments
Labels
bug Confirmed bug
Milestone

Comments

@brocoli12138
Copy link

I found that the async_publish_time.cpp file cannot send timestamp messages correctly.
To find out why, I canceled the "send when dissconnected" connect option. It showed me that connection had been closed before publishment.
the code here is what I changed.
auto createOpts = mqtt::create_options_builder()
.send_while_disconnected(true, true)
.max_buffered_messages(MAX_BUFFERED_MESSAGES)
.delete_oldest_messages()
.finalize();

I change this part of code into this:

auto createOpts = mqtt::create_options_builder()
// .send_while_disconnected(true, true)
.max_buffered_messages(MAX_BUFFERED_MESSAGES)
.delete_oldest_messages()
.finalize();

Then I compile and execute this code, still can not receive message on server side.
This is part of code from "async_publish.cpp"

cout << "\nConnecting..." << endl;
mqtt::token_ptr conntok = client.connect(connOpts);
cout << "Waiting for the connection..." << endl;
conntok->wait();
cout << " ...OK" << endl;

and this is part of code from ”async_publish_time.cpp“:

cout << "Starting connection..." << endl;
cli.connect(connOpts);
auto top = mqtt::topic(cli, "data/time", QOS);
cout << "Publishing data..." << endl;

What's the difference? It is "->wait()"!!!! right!
After I corrected the ”async_publish_time.cpp“ into this:

cout << "Starting connection..." << endl;
cli.connect(connOpts)->wait();
auto top = mqtt::topic(cli, "data/time", QOS);
cout << "Publishing data..." << endl;

Then, I can publish data/time properly!

@fpagliughi
Copy link
Contributor

Oh, yes, I see it. You're right. I will fix it.

@fpagliughi fpagliughi added the bug Confirmed bug label Jan 5, 2025
@fpagliughi fpagliughi added this to the v1.5 milestone Jan 5, 2025
@fpagliughi fpagliughi added the fix added A fix has been pushed to the repo and is being tested label Jan 5, 2025
@fpagliughi
Copy link
Contributor

Oh, actually I did all that before I noticed my own comment...

        // Note that we start the connection, but don't wait for completion.
        // We configured to allow publishing before a successful connection.

This means I was specifically demonstrating a feature of the Paho C library where you should be allowed to publish messages before you're connected.

I need to look at this further.

@fpagliughi fpagliughi removed the fix added A fix has been pushed to the repo and is being tested label Jan 5, 2025
@fpagliughi fpagliughi modified the milestones: v1.5, v1.6 Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

2 participants