-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_ws.py
More file actions
61 lines (49 loc) · 2.45 KB
/
test_ws.py
File metadata and controls
61 lines (49 loc) · 2.45 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import asyncio
import websockets
import ssl
import logging
# --- Set the URL to test ---
TEST_URI = "wss://home-1-evanp.duckdns.org:5000/waterfall"
# --- This adds extra debug logging (uncomment if needed) ---
# logging.basicConfig(level=logging.INFO)
# logging.getLogger('websockets').setLevel(logging.DEBUG)
async def test_websocket():
print(f"\n--- Attempting to connect to: {TEST_URI} ---")
# We create a default SSL context
ssl_context = ssl.create_default_context()
try:
# --- THIS IS THE FIXED LINE ---
# I've replaced the broken asyncio.wait_for with the
# built-in 'open_timeout' parameter.
async with websockets.connect(TEST_URI, ssl=ssl_context, open_timeout=10.0) as websocket:
print("\n✅ --- SUCCESS: Connection Established! ---")
print(f" Server: {websocket.response_headers.get('Server')}")
print(" Waiting for first message...")
try:
# This part was already correct: wait 5s for a message
message = await asyncio.wait_for(websocket.recv(), timeout=20.0)
print(f" SUCCESS: Received message! Length: {len(message)}")
except asyncio.TimeoutError:
print(" WARNING: Connection opened, but no message received after 5 seconds.")
# This will catch the 'open_timeout'
except asyncio.TimeoutError:
print(f"\n❌ --- FAILED: Connection Timed Out ---")
print(" This is an 'ETIMEDOUT'. The router or a firewall is dropping the packet.")
print(" This points to your AT&T router blocking port 443.")
# This will catch the 'readyState: 3' error
except websockets.exceptions.ConnectionClosedError as e:
print(f"\n❌ --- FAILED: Connection Closed (Error) ---")
print(f" Code: {e.code}")
print(f" Reason: {e.reason}")
print(" This is the Python equivalent of 'readyState: 3'.")
print(" The server (Nginx) *is* answering but slammed the door.")
except (ConnectionRefusedError, OSError) as e:
print(f"\n❌ --- FAILED: Connection Refused or OS Error ---")
print(f" Error: {e}")
print(" This means the router/firewall actively rejected the connection on port 443.")
except Exception as e:
print(f"\n❌ --- FAILED: An unexpected error occurred ---")
print(f" Type: {type(e)}")
print(f" Error: {e}")
if __name__ == "__main__":
asyncio.run(test_websocket())