diff --git a/test/compatibility/python/websockets/devnull_client.py b/test/compatibility/python/websockets/devnull_client.py new file mode 100644 index 00000000..b4325fe7 --- /dev/null +++ b/test/compatibility/python/websockets/devnull_client.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +# websocket send client + +import argparse +import asyncio +import websockets + +try: + import uvloop + uvloop.install() +except ImportError: + print('uvloop not available') + pass + +msgCount = 0 + +async def timer(): + global msgCount + + while True: + print(f'Received messages: {msgCount}') + msgCount = 0 + + await asyncio.sleep(1) + + +async def client(url): + global msgCount + + asyncio.ensure_future(timer()) + + async with websockets.connect(url) as ws: + async for message in ws: + msgCount += 1 + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='websocket proxy.') + parser.add_argument('--url', help='Remote websocket url', + default='wss://echo.websocket.org') + args = parser.parse_args() + + asyncio.get_event_loop().run_until_complete(client(args.url))