-
Notifications
You must be signed in to change notification settings - Fork 0
/
websocket_client.py
40 lines (29 loc) · 1005 Bytes
/
websocket_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import aiohttp
import asyncio
ADDRESS="ws://127.0.0.1:1111/"
REQUEST_DATA = b"test message"
TIMEOUT = 60.0
async def test():
ws_session = aiohttp.ClientSession()
running = True
multiplier = 1
while running:
try:
async with ws_session.ws_connect(
ADDRESS,
) as ws:
data = REQUEST_DATA * multiplier
print("------------------- SENDING ------------------- ", len(data), " bytes")
await ws.send_bytes(data + b" " + str(len(data)).encode("ascii"))
ws_response = await ws.receive(TIMEOUT)
print("------------------- RESPONSE -------------------")
print(ws_response.data)
print("------------------------------------------------")
multiplier *= 2
except asyncio.CancelledError:
running = False
await ws_session.close()
try:
asyncio.run(test())
except KeyboardInterrupt:
pass