client_connection.py 文件源码

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

项目:parsec-cloud 作者: Scille 项目源码 文件源码
def websocket_route_factory(execute_cmd, base_dispatcher):

    async def on_connection(request):
        ws = web.WebSocketResponse()
        await ws.prepare(request)
        context = WebsocketClientConnectionContext(ws)
        client_dispatcher = client_dispatcher_factory(context)
        session = SessionComponent()
        dispatcher = ComposedDispatcher([
            base_dispatcher, client_dispatcher, session.get_dispatcher()])
        context.logger.info('Connection started')
        try:
            handshake_dispatcher = ComposedDispatcher([
                dispatcher, handshake_io_dispatcher_factory(context)])
            await asyncio_perform(handshake_dispatcher, session.handshake())
        except (HandshakeError, WebsocketConnectionClosed):
            context.logger.info('Bad handshake, closing connection')
            return ws
        context.logger.debug('Handshake done, `%s` is authenticated.' % session.id)
        await _on_connection_main_loop(execute_cmd, context, dispatcher)
        context.logger.info('Connection closed by client')
        return ws

    return on_connection
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号