lcm-proj / lcm

Lightweight Communications and Marshalling
GNU Lesser General Public License v2.1
981 stars 388 forks source link

Multiple hosts's IP need to be set the same subnet when communicating each other? #274

Open liyingzhi opened 5 years ago

liyingzhi commented 5 years ago

System info:

  1. The talker at B host multicasts a message named 'EXAMPLE' to the network. The listener at B host can receive the message and enter the handle function. But the listener at A host never enter the handle function. Then i use Wireshark to monitor the network data at A host, the message from B host can be obtained by A host.

Test2:

  1. The talker at B host multicasts a message named 'EXAMPLE' to the network. The listeners at A and B host both receive the message and enter the handle function. The situation at Test1_2 does not happen!

Is there a problem with my A host configuration? Or multiple hosts's IP need to be set the same subnet when communicating each other?

Thank you and looking forward to your reply.

Codes:

using namespace std;

class Handler { public: ~Handler() {} void handleMessage(const lcm::ReceiveBuffer rbuf, const std::string &chan, const lcm_std_msgs::Header msg) { int i; printf("Received message on channel \"%s\":\n", chan.c_str()); printf(" timestamp = %lld\n", (long long)msg->seq); printf(" position = (%f, %f, %f)\n", msg->stamp); cout << msg->frame_id << endl; } };

int main(int argc, char *argv[]) { string address = "udpm://239.1.1.255:7667?ttl=1"; int i; lcm::LCM lcm(address) ; if (!lcm.good()) return 1; Handler handlerObject; lcm.subscribe("EXAMPLE", &Handler::handleMessage, &handlerObject);

while (0 == lcm.handle()) {
    // Do nothing
}

return 0;

}


****