python - Can pyzmq publishers be operated from class instances? -
i have following code publisher, instantiates few class instances , publishes messages. however, don't receive @ subscriber side. publisher import zmq import time multiprocessing import process class senddata: def __init__(self, msg, port): self.msg = msg self.port = port ctx = zmq.context() self.sock = ctx.socket(zmq.pub) self.sock.bind('tcp://127.0.0.1:'+str(self.port)) time.sleep(1) def sender(self): self.sock.send_json(self.msg) def main(): device, port in zip(['2.2.2.2', '5.5.5.5'],[5001, 5002]): msg = {device:'some random message'} instance = senddata(device, port) process(target=instance.sender).start() if __name__ == "__main__": main() subscriber import zmq ctx = zmq.context() recv_sock1 = ctx.socket(zmq.sub) recv_sock1.connect('tcp://127.0.0.1:5001') recv_sock1.setsockopt(zmq.subscribe, '') recv_sock2