Created
February 12, 2019 18:44
-
-
Save codeif/5a0b69335a1482e692801e51b8fc5950 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aiohttp | |
import asyncio | |
async def main(): | |
session = aiohttp.ClientSession() | |
ws = await session.ws_connect( | |
'wss://ws.example.com/channel') | |
while True: | |
msg = await ws.receive() | |
if msg.type == aiohttp.WSMsgType.TEXT: | |
if msg.data == 'close': | |
await ws.close() | |
break | |
else: | |
print(msg.data) | |
# ws.send_str(msg.data + '/answer') | |
elif msg.tp == aiohttp.MsgType.closed: | |
break | |
elif msg.tp == aiohttp.MsgType.error: | |
break | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment