-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_client.py
More file actions
executable file
·38 lines (31 loc) · 1.03 KB
/
test_client.py
File metadata and controls
executable file
·38 lines (31 loc) · 1.03 KB
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
#!/usr/bin/env python3
"""
Simple WebSocket client to test the chip-tool-rs server
"""
import asyncio
import websockets
import sys
async def test_client():
uri = "ws://localhost:9002"
try:
async with websockets.connect(uri) as websocket:
print(f"Connected to {uri}")
# Send some test messages
messages = [
"Hello from test client",
"This is a test message",
'{"command": "test", "data": "json payload"}',
"Final test message"
]
for msg in messages:
print(f"Sending: {msg}")
await websocket.send(msg)
await asyncio.sleep(0.5)
print("All messages sent successfully")
await websocket.close()
print("Connection closed")
except Exception as e:
print(f"Error: {e}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
asyncio.run(test_client())