From 196f3d4b8a308a076100ab32c1b339206f22e35d Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Sat, 4 Jan 2020 15:13:05 -0800 Subject: [PATCH] Add a simple python program to send a file (debugging #140) --- .../python/websockets/small_file | 1 + .../python/websockets/ws_send.py | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/compatibility/python/websockets/small_file create mode 100644 test/compatibility/python/websockets/ws_send.py diff --git a/test/compatibility/python/websockets/small_file b/test/compatibility/python/websockets/small_file new file mode 100644 index 00000000..a4cfdfef --- /dev/null +++ b/test/compatibility/python/websockets/small_file @@ -0,0 +1 @@ +not much in here diff --git a/test/compatibility/python/websockets/ws_send.py b/test/compatibility/python/websockets/ws_send.py new file mode 100644 index 00000000..f7da1953 --- /dev/null +++ b/test/compatibility/python/websockets/ws_send.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 + +# websocket send client + +import argparse +import asyncio +import websockets + + +async def send(url, path): + async with websockets.connect(url, ping_timeout=None, ping_interval=None) as ws: + with open(path, 'rb') as f: + message = f.read() + + print('Sending message...') + await ws.send(message) + print('Message sent.') + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='websocket proxy.') + parser.add_argument('--path', help='Path to the file to send.', + default='small_file') + parser.add_argument('--url', help='Remote websocket url', + default='wss://echo.websocket.org') + args = parser.parse_args() + + asyncio.get_event_loop().run_until_complete(send(args.url, args.path))