

def on_message(self, msg):
    "Callback: web socket has received a message.\n        \n        Note that message is a string here. The UTF-8 bytes have been decoded,\n        but it hasn't been de-jsoned.\n        "
    if ((not self.twconn) or (not self.twconn.available)):
        self.application.twlog.warning('Websocket connection is not available')
        self.write_tw_error('Your connection is not registered.')
        return
    self.twconn.lastmsgtime = twcommon.misc.now()
    if (not self.application.twservermgr.tworldavailable):
        self.application.twlog.warning('Tworld is not available.')
        ex.write_tw_error('Tworld service is not available.')
        return
    if (not msg.startswith('{')):
        self.application.twlog.warning('Message from client appeared invalid: %s', msg[0:50])
        self.write_tw_error('Message format appeared to be invalid.')
        return
    if (len(msg) > 1000):
        self.application.twlog.warning('Message from client was too long: %s', msg[0:50])
        self.write_tw_error('Message was too long.')
        return
    try:
        self.application.twservermgr.tworld_write(self.twconnid, msg)
    except Exception as ex:
        self.application.twlog.error('Could not pass message to tworld socket: %s', ex)
        self.write_tw_error(('Unable to pass command to service: %s' % (ex,)))

dataset/ETHPy150Open erkyrath/tworld/lib/tweblib/handlers.py PlayWebSocketHandler.on_message/VarMisuse@95/217 `self`->`ex`