Files
itgmania212121/extern/IXWebSocket-11.3.2/test/compatibility/python/websockets/ws_send.py
T
Martin Natano dc49af3c59 Implement NetworkManager
For now there are two methods:

- `NETWORK:IsUrlAllowed()`: Check whether access to a certain URL is allowed.
- `NETWORK:HttpRequest()`: Perform an HTTP request.

By default access to the network is disabled for all target hosts. It
can be enabled by setting `HttpEnable=1` in the preferences. Individual
hosts have to be added to `HttpAllowHosts` as a comma separated list to
allow access.

See included docs for more details on usage.
2022-01-15 22:56:08 +01:00

29 lines
819 B
Python

#!/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))