如何捕获sendMessage错误?没有异常传播。当服务器关闭(半开连接)时,我想在我的客户端代码中捕获错误。如果运行websocket守护程序的服务器崩溃,重新启动,丢失网络连接,则closeConnection / ConnectionLost / ConnectionFailed回调不起作用。
from autobahn.websocket import WebSocketClientProtocol
class ClientProtocol(WebSocketClientProtocol):
def onOpen(self):
def heartbeat():
self.sendMessage("HB")
self.factory.reactor.callLater(1, heartbeat)
# I want to catch a socket error
try:
heartbeat()
except Exception as e:
print e
也许有更好的解决方案。乒乓 ?简单地说,我无法找到我的客户端如何检测服务器崩溃/重新启动然后重新连接的方式。
我正在使用高速公路0.6.5