def __init__(self): pull = context.socket(zmq.PULL) # Incoming messages pull.bind("tcp://*:5555") pub = context.socket(zmq.PUB) # Distributing messages pub.bind("tcp://*:5556") self.pull = pull self.pub = pub lib.spawn(self.listen, name='listen')
def __init__(self, author, peers): self.author = author self.peers = peers push = context.socket(zmq.PUSH) push.connect("tcp://192.168.1.2:5555") sub = context.socket(zmq.SUB) sub.setsockopt(zmq.SUBSCRIBE, '') sub.connect("tcp://192.168.1.2:5556") self.push = push self.sub = sub lib.spawn(self.listen, name='listen') self.catchup()
logger.setLevel(logging.DEBUG) def main(): context = zmq.Context() socket = context.socket(zmq.SUB) socket.connect('tcp://localhost:5556') socket.setsockopt(zmq.SUBSCRIBE, 'log') print "Running logger.." while True: header, body = socket.recv_multipart() message = json.loads(body) log = protocol.Log.from_dict(message) write = getattr(logger, log.level) write("{}: {}".format(log.trace, log.string)) if __name__ == '__main__': lib.spawn(main) while True: try: time.sleep(1) except KeyboardInterrupt: print "\nGood bye" break