eclipse-paho / eclipse-paho/paho.mqtt.cpp
The async_publish_time.cpp code has a bug: the connection is closed before starting to publish timestamp messages
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1.3k
- Forks
- 476
- PR merge metrics
- No merged PRs in 30d
Description
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!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with async_publish_time.cpp and compare its connection sequence with async_publish.cpp, especially whether cli.connect(connOpts) is waited on before publishing. Confirm the example establishes the connection before creating the topic and sending timestamp messages; done means the server receives data/time messages reliably.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100