Exemplo n.º 1
0
 def recv(self):
     try:
         data = self.socket.recv()
         msg = Message.unserialize(data)
     except msgerr.ExtraData as e:
         raise RPCError("ZMQ interrupted message") from e
     except zmqerr.ZMQError as e:
         raise RPCError("ZMQ network broken") from e
     return msg
Exemplo n.º 2
0
 def recv_from_client(self):
     try:
         data = self.socket.recv_multipart()
         addr = data[0].decode()
         msg = Message.unserialize(data[1])
     except (UnicodeDecodeError, msgerr.ExtraData) as e:
         raise RPCError("ZMQ interrupted message") from e
     except zmqerr.ZMQError as e:
         raise RPCError("ZMQ network broken") from e
     return addr, msg
Exemplo n.º 3
0
 def __init__(self, host, port):
     BaseSocket.__init__(self, zmq.ROUTER)
     if port == 0:
         self.port = self.socket.bind_to_random_port("tcp://%s" % host)
     else:
         try:
             self.socket.bind("tcp://%s:%i" % (host, port))
             self.port = port
         except zmqerr.ZMQError as e:
             raise RPCError("Socket bind failure: %s" % (e))
Exemplo n.º 4
0
 def close(self):
     raise RPCError()
Exemplo n.º 5
0
 def recv_from_client(self):
     results = self.queue.get()
     msg = Message.unserialize(results)
     if msg.data == NETWORK_BROKEN:
         raise RPCError()
     return msg.node_id, msg
Exemplo n.º 6
0
 def send_to_client(self, msg):
     try:
         self.socket.send_multipart([msg.node_id.encode(), msg.serialize()])
     except zmqerr.ZMQError as e:
         raise RPCError("ZMQ sent failure") from e
Exemplo n.º 7
0
 def send(self, msg):
     try:
         self.socket.send(msg.serialize(), zmq.NOBLOCK)
     except zmqerr.ZMQError as e:
         raise RPCError("ZMQ sent failure") from e