【发布时间】:2019-01-29 12:25:56
【问题描述】:
假设 WebSocket 服务器暂时关闭,它丢弃传入的数据包(而不是拒绝它们)
目前,连接尝试和TimeoutError之间大约需要 95 秒
我似乎找不到减小该窗口的方法(所以我可以尝试另一个 WebSocket 服务器)
这是我正在运行的演示代码:(刚刚取自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))
【问题讨论】:
标签: python python-3.x websocket