anyio的websocket协议实现
anysocks的Python项目详细描述
任何袜子
这个库基于Sans-IO library wsproto实现the WebSocket protocol。 i/o由anyio project处理,这使得这个库与asyncio、trio和curio兼容。
安装
这个库需要Python3.5+。您可以直接从pypi安装它:
python3 -m pip install -U anysocks
如果您希望使用尖端的开发版本,请直接从github安装:
python3 -m pip install -U git+https://github.com/clamor-py/anysocks@master#egg=anysocks
文档
本自述文件仅提供一个简短的概述,请参阅完整的文档here。
示例
importanyiofromanysocksimportopen_connectionasyncdefmain():asyncwithopen_connection('wss://echo.websocket.org')ascon:print('Connection established!')# First, let's send some text to the server.text=input('What to send? ')awaitcon.send(text)# Now, we receive and verify the server's response.message=awaitcon.get_message()assertmessage==text,"Received {}, expected {}".format(message,text)print('Connection closed with code {}',con.close_code.value)anyio.run(main)