1

I have two machines in the same network :

  1. The first machine binds to a socket on its own IP address (120.0.0.1) and receives any data coming to the socket .bind()-ed on port 5555:

    zmq::context_t context{1};   
    zmq::socket_t socket{context, ZMQ_SUB};
    socket.setsockopt(ZMQ_SUBSCRIBE,  "lidar");
    
    socket.bind("tcp://120.0.0.1:5555");
    
    while(true)
    {
       zmq::message_t message;
       auto recv = socket.recv(message);
       ROS_INFO("Value: %d", recv.value());
    }
    
  2. The second machine, having an IP address 120.0.0.248, connects to the first machine and sends the messages to it:

    sock.connect("tcp://120.0.0.1:5555");
    while (1) {
      double nodes[8192];
      sock.send(zmq::buffer("lidar") , zmq::send_flags::sndmore);
      sock.send(zmq::buffer(nodes, (((int)(count)) * 8)));
    }
    

But for some reason, I cannot receive any messages on the first machine and it gets stuck on auto recv = socket.recv(message);.

What is a correct way for such communication?

user3666197
  • 1
  • 6
  • 50
  • 92
aikhs
  • 949
  • 2
  • 8
  • 20
  • Would you mind to show the complete code? This is by far not an MCVE code, is it? – user3666197 Jun 16 '20 at 17:00
  • Is your sender a PUB socket? I would normally bind the PUB socket ("the server") and connect the SUB sockets ("the clients"). – rveerd Jun 26 '20 at 14:43

0 Answers0