(self, message)
When a new message is received.
When a new message is received.
When a new message is received .
def received_message(self, message):
        """ When a new message is received. """

        # We do not support binary message
        if message.is_binary:
            return False

        try:
            protocol, data = json.loads(message.data.decode('utf8'))
        except ValueError:
            # If error while parsing JSON
            # if unpack error: more then 2 items in the list
            logging.getLogger(__name__).exception(
                "Error parsing incoming message: {}".format(
                    message.data.decode("utf8")))

            return

        if _DEBUG:
            logging.getLogger(__name__).info("Receiving {}".format(data))

        handler = self.handlers.get(protocol)

        if handler:
            handler._receive_protocol(data)  # pylint: disable=protected-access
        else:
            logging.getLogger(__name__).warning(
                "Unknown protocol received: {}, {}".format(protocol, data))
def received_message ( self , message ) : # We do not support binary message if message . is_binary : return False try : protocol , data = json . loads ( message . data . decode ( 'utf8' ) ) except ValueError : # If error while parsing JSON # if unpack error: more then 2 items in the list logging . getLogger ( __name__ ) . exception ( "Error parsing incoming message: {}" . format ( message . data . decode ( "utf8" ) ) ) return if _DEBUG : logging . getLogger ( __name__ ) . info ( "Receiving {}" . format ( data ) ) handler = self . handlers . get ( protocol ) if handler : handler . _receive_protocol ( data ) # pylint: disable=protected-access else : logging . getLogger ( __name__ ) . warning ( "Unknown protocol received: {}, {}" . format ( protocol , data ) )