ws_journal.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:monetta 作者: hgn 项目源码 文件源码
def handle(request):
    peername = request.transport.get_extra_info('peername')
    host = port = "unknown"
    if peername is not None:
        host, port = peername[0:2]
    log.debug("web journal socket request from {}[{}]".format(host, port))

    ws = web.WebSocketResponse()
    await ws.prepare(request)

    jh = JournalHandler(ws)
    async for msg in ws:
        if msg.type == aiohttp.WSMsgType.TEXT:
            if msg.data == 'close':
                await ws.close()
                await jh.shutdown()
                return ws
            if msg.data == 'info':
                jh.sync_info()
            elif msg.data == 'history':
                jh.sync_history()
            elif msg.data == 'journal-sync-start':
                jh.sync_log()
            elif msg.data == 'journal-sync-stop':
                jh.journal_sync_stop()
            else:
                log.debug("unknown websocket command {}".format(str(msg.data)))
        elif msg.type == aiohttp.WSMsgType.ERROR:
            print('ws connection closed with exception %s' % ws.exception())
    return ws
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号