【websockets】python使用websockets库调用websocket接口

class WsClient(object):
    def __init__(self, url):
        self.url = url

    async def test(self):
        async with websockets.connect(self.url + '/test') as websocket:
            await websocket.send('{"chan": "test"}')
            while True:
                recv_text = await websocket.recv()
                debug_logger.info(recv_text)

    def run_test(self):
        asyncio.get_event_loop().run_until_complete(self.test())

 

posted @ 2022-02-16 20:36  代码诠释的世界  阅读(865)  评论(0编辑  收藏  举报