You didn't post the whole code, so I can only guess what is happening.
My suspicion is that this is called somewhere once from your main after startup. In that case the publish line is called, but there are no subscribers connected yet. Just wait until vel_pub_.getNumSubscribers() > 0 and then execute one command.
Originally posted by dornhege with karma: 31395 on 2012-11-23
This answer was ACCEPTED on the original site
Post score: 0
Original comments
Comment by Nap on 2014-05-18:
That explains a problem I've been having. However that is a ridiculous design. A publisher should not be concerned about subscribers, that is ROSCORE's job. So now I have to advertise my node, and then check if anyone is interested?
Comment by dornhege on 2014-05-18:
Everything is working as intended. You can and usually should publish without worrying if anyone is connected - unless you have some requirement to explicitly check for that.
Comment by Nap on 2014-05-25:
@dornhedge, I really appreciate the answer you gave above because I had run out of ideas and it fixed the problem. However, what do you mean by usually and unless?
If there are no subscribers, either the message is bufferer (in accordance to the buffer parameter) or the message is dropped.
But in my case, the subscriber was there listening but didn't receive anything. And similar to Zoroth's case, having a loop made the difference. This doesn't seem to me how it was intended to be?