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

Problem: cannot receive the first message from server #1012

Closed
lin0303-siyuan opened this issue Mar 14, 2023 · 2 comments
Closed

Problem: cannot receive the first message from server #1012

lin0303-siyuan opened this issue Mar 14, 2023 · 2 comments

Comments

@lin0303-siyuan
Copy link

Problem Description

When I try the online tutorial sample, I built a client and a server side. It happens that the client cannot get the message from server under any condition. I try to start client first and start server first instead, none of them works. I don't know why. I know that if the callback function doesn't process as fast as server sends the message, there will be a message drop. But I let the server sends message at a much lower frequency. See the code below. So can anybody help me out of it? Really appreciate it.

Client (subscriber) code
image
Server (publisher) code
image

How to reproduce

The client would never receive the first message: "Received Message: Hello World 1"

How did you get eCAL?

Ubuntu PPA (apt-get)

Environment

  • ecal: v5.11.3
  • OS: Ubuntu
  • build in C++14
  • cmake 3.16.0

eCAL System Information

No response

@FlorianReimold
Copy link
Member

FlorianReimold commented Mar 14, 2023

Hi @lin0303-siyuan,

tl;dr: eCAL always needs a little time to start up. By default, 1 seconds. If you sleep >1s before publishing your first message, you should receive it.

Long explanation
In eCAL, 2 different communications are always happening simultaneously.

  1. The data-communication is what you are actually seeing. This transports the payload, in your case the "Hello World" Strings.
  2. In the background, hidden from you, eCAL however has to send around some metadata. This metadata is for instance responsible for individual nodes finding each other.

In order to have a successful connection from a publisher to a subscriber, the following information have to be exchanged:

  • The publisher must receive the information that a subscriber for its topic exists and where it lives (to determine the data transport layer like UDP for network or SHM for localhost). While the eCAL API already allows you to publish data without having a subscriber, the eCAL library will simply do nothing if there is no subscriber, in order to save system resources.
  • The subscriber must receive information from the publisher about how the data will be transmitted. Again, it must know about the concrete layer (UDP, TCP, SHM), as well as the layer parameters (Port for TCP, SHM filename for SHM)

Only after these information have been exchanges successfully, the data communcation can start. The metadata is however only transmitted once every 1s. Therefore, if you call publisher.Send() directly after you created the publisher, eCAL didn't have enough time for publisher <-> subscriber matching, yet.

You should easily be able to work around this, by adding a delay between the instantiation of your publisher and the first Send() call. For instance, you can move the std::chrono::sleep_for to the beginning of the while loop, so that eCAL has some time to establish all connections.

Kind Regards
Florian

@lin0303-siyuan
Copy link
Author

Really appreciate your answer, it solved my problem. It's such a nice explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants