我正在运行一个Autobahn WS服务器,并使用Python websocket-client(https://pypi.python.org/pypi/websocket-client/)从客户端连接到它。
我的客户端代码非常简单: -
from websocket import create_connection
# WS_URL is a valid endpoint
ws = None
try:
ws = create_connection(WS_URL)
except:
print 'Could not connect to websocket server ...'
sample_message = "Hello world"
while True:
if ws is not None:
ws.send(sample_message)
这种方法有效一段时间,但后来我看到了错误: -
错误:[Errno 104]通过对等方重置连接
搜索,似乎与某种超时错误有关。任何人都可以建议如何解决这个问题?
更新
为了确认服务器端,WS服务器只是使用Autobahn docs中的股票“广播”示例 - https://github.com/tavendo/AutobahnPython/blob/master/examples/websocket/broadcast/server.py。因此,从客户端收到的消息只会回显给所有连接的客户端。
UPDATE2
感谢调试提示。我运行了这个,当发生错误时,这是调试跟踪的输出: -
2013-10-16 12:47:47+0000 [BroadcastServerProtocol,0,172.20.12.9] WebSocketProtocol.onClose:
wasClean=False
code=1006
reason=connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)
self.closedByMe=False
self.failedByMe=False
self.droppedByMe=False
self.wasClean=False
self.wasNotCleanReason=peer dropped the TCP connection without previous WebSocket closing handshake
self.localCloseCode=None
self.localCloseReason=None
self.remoteCloseCode=None
self.remoteCloseReason=None
为什么连接断开了?该错误可以再现并在约。每次运行的同一时间(约5小时)。