I have a zmq publisher in c++ (using zhelpers.hpp) and zmq subscriber in python3 (using pyzmq). Trouble is, no message is recived in subscriber. I suppose, there is a problem with zmq filter. I cant figure out, how to properly use setsockopt in c++ to recive messages from python publisher.
Python publisher:
import zmq
context = zmq.Context()
socket = context.socket(zmq.PUB)
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:4004")
while True:
command = input("insert command ")
if (command=='c'):
topic = "CALL".encode("ascii")
data = "blabla".encode("ascii")
socket.send_multipart([topic,data])
C++ subscriber:
#include "zhelpers.hpp"
zmq::context_t context(1);
zmq::socket_t subscriber1 (context, ZMQ_SUB);
subscriber1.connect("tcp://127.0.0.1:4004");
subscriber1.setsockopt( ZMQ_SUBSCRIBE, "CALL", 4);
while (1) {
// read envelope
std::string address = s_recv (subscriber1);
// read message
std::string contents = s_recv (subscriber1);
std::cout << "[" << address << "] " << contents << std::endl;
Python subscriber is workking fine. Code:
subscriber = context.socket(zmq.SUB)
subscriber.connect("tcp://127.0.0.1:4004")
subscriber.setsockopt(zmq.SUBSCRIBE, b"CALL")
[command, contents] = self.subscriber.recv_multipart()
Aucun commentaire:
Enregistrer un commentaire