【发布时间】:2021-05-03 08:49:47
【问题描述】:
我正在尝试为cyclonedds 中的发布者使用侦听器。但是 CycloneDDS 没有任何例子。 有人可以在code 中解释如何使用它们吗?
来自上面的链接,the publisher sending data part
对于这个例子,我们希望有一个订阅者来实际阅读 我们的信息。这并不总是必要的。还有,它的样子 在这里完成只是为了说明最简单的方法。它不是 但是,确实建议在轮询循环中等待。
请查看 Listeners 和 WaitSets 以获得更好的效果 解决方案,尽管更复杂一些。
std::cout << "=== [Publisher] Waiting for subscriber." << std::endl;
while (writer.publication_matched_status().current_count() == 0) { // how to use a listener here?
std::this_thread::sleep_for(std::chrono::milliseconds(20));
}
HelloWorldData::Msg msg(1, "Hello World");
writer.write(msg);
等待订阅者停止以确保它收到了通常不需要的消息,因此不建议在轮询循环中执行此操作。
std::cout << "=== [Publisher] Waiting for sample to be accepted." << std::endl;
while (writer.publication_matched_status().current_count() > 0) {// how to use a listener here?
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
【问题讨论】:
标签: eclipse listener data-distribution-service