3

我正在运行 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 文档中的股票“广播”示例 - https://github.com/tavendo/AutobahnPython/blob/master/examples/websocket/broadcast/server.py。因此,从客户端接收到的消息只会回显给所有连接的客户端。

更新2

感谢您的调试提示。我运行了这个,当错误发生时,这是调试跟踪的输出:-

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

为什么连接断开了?该错误可以重现,并在大约 10 分钟后发生。每次运行相同的时间(约 5 小时)。

4

0 回答 0