-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_websocket.py
More file actions
35 lines (27 loc) · 1019 Bytes
/
test_websocket.py
File metadata and controls
35 lines (27 loc) · 1019 Bytes
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
import asyncio
import websockets
import json
import base64
async def test_websocket():
uri = "ws://localhost:8000/ws/streaming-stt/test-client"
try:
async with websockets.connect(uri) as websocket:
print("🔗 Connected to WebSocket")
# Wait for status message
response = await websocket.recv()
print(f"📩 Received: {response}")
# Send a ping
ping_message = {
"type": "ping",
"data": {"timestamp": "test"}
}
await websocket.send(json.dumps(ping_message))
print("📤 Sent ping")
# Wait for pong
response = await websocket.recv()
print(f"📩 Received: {response}")
print("✅ WebSocket test successful")
except Exception as e:
print(f"❌ WebSocket test failed: {e}")
if __name__ == "__main__":
asyncio.run(test_websocket())