Let's say that the WebSocket server is temporary down, and it drops incoming packets (rather than rejecting them)
Currently, it takes around 95 seconds between the connection attempt and the TimeoutError
I can't seem to find a way to reduce that window (so I can try another WebSocket server)
This is the demo code that I am running: (just taken from the official docs
#!/usr/bin/env python
import asyncio
import websockets
import os
import socket
import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)-8s [%(name)s.%(funcName)s:%(lineno)d]: %(message)s', datefmt='%m-%d %H:%M:%S', )
host = os.environ.get('SERVER_URL','localhost:9090')
self_id = os.environ.get('SELF_ID',socket.gethostname())
connect_url =f'ws://{host}/{self_id}'
logging.info(f'Connect to: {connect_url}')
async def hello(uri):
logging.info(f'Connecting to {uri}')
async with websockets.connect(uri, timeout=1, close_timeout=1) as websocket:
logging.info(f"Conected to {uri}")
async for message in websocket:
await websocket.send(message)
asyncio.get_event_loop().run_until_complete(
hello(connect_url))