Add a simple python program to send a file (debugging #140)
This commit is contained in:
parent
162e228b34
commit
196f3d4b8a
1
test/compatibility/python/websockets/small_file
Normal file
1
test/compatibility/python/websockets/small_file
Normal file
@ -0,0 +1 @@
|
|||||||
|
not much in here
|
28
test/compatibility/python/websockets/ws_send.py
Normal file
28
test/compatibility/python/websockets/ws_send.py
Normal file
@ -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))
|
Loading…
x
Reference in New Issue
Block a user