【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())

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM