server.py 文件源码

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

项目:monopoly-open-bid 作者: Rosuav 项目源码 文件源码
def websocket(req):
    ws = web.WebSocketResponse()
    await ws.prepare(req)
    async for msg in ws:
        if msg.type != WSMsgType.TEXT: continue
        try:
            msg = json.loads(msg.data)
            if msg["type"] != "login": continue
            room = msg["data"]["room"][:32]
            if room: break
        except (ValueError, KeyError, TypeError):
            # Any parsing error, just wait for another message
            continue
    else:
        # Something went wrong with the handshake. Kick
        # the client and let them reconnect.
        await ws.close()
        return ws
    if room not in rooms: Room(room)
    return await rooms[room].websocket(ws, msg["data"])

# After all the custom routes, handle everything else by loading static files.
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号