def recv_json(self): """ Receive json Return tuple of: message_type, message """ message_type = self.sock.recv() logger.debug('Recv message of type: %s', message_type) wire_message = self.sock.recv() message = json.loads(wire_message) return message_type, message
def send_json(self, message_type, message=None, target=None): logger.debug('Send message of type %s to %s', message_type, target) # send target info if target: self.sock.send(target, zmq.SNDMORE) self.sock.send('', zmq.SNDMORE) # send message type self.sock.send(message_type, zmq.SNDMORE) # send message wire_message = json.dumps(message) logger.debug('Payload: %s', wire_message) self.sock.send(wire_message)