def _receive_message(self, name, socket):
"""
Receives an incoming message from a ZMQ socket.
:param str name: The name of the end point of source of the message.
:param zmq.sugar.socket.Socket socket: The ZMQ socket.
"""
buffer = socket.recv()
if buffer[:1] == b'{':
tmp = jsonapi.loads(buffer)
if tmp['type'] not in self._json_message_creators:
raise ValueError("Received JSON message with unknown message type '{0}'".format(tmp['type']))
message = self._json_message_creators[tmp['type']](tmp)
else:
message = pickle.loads(buffer)
""":type: enarksh.message.Message.Message"""
message.message_source = name
if message.message_type not in self.__message_types:
raise ValueError("Received message with unknown message type '{0}'".format(message.message_type))
event = self.__message_types[message.message_type]
event.fire(message)
# ------------------------------------------------------------------------------------------------------------------
评论列表
文章目录