[英]Autobahn: catch sendMessage error
how can I catch sendMessage error ? 如何捕获sendMessage错误? There is no exception propagation.
没有异常传播。 When the server is down (half-open connection) I want catch the error in my client code.
当服务器关闭(半开放连接)时,我想在我的客户端代码中捕获该错误。 If the server running the websocket daemon crashes, reboots, loses network connectivity closeConnection/ConnectionLost/ConnectionFailed callbacks does not work.
如果运行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
Maybe there are better solutions than this. 也许有比这更好的解决方案。 Ping Pong ?
乒乓 ? Simply I cannot find a way how my client can detect server crash/reboots then reconnect.
简而言之,我找不到我的客户端可以检测到服务器崩溃/重新启动然后重新连接的方式。
I am using autobahn 0.6.5 我正在使用高速公路0.6.5
Yes, there is a better solution for fast detection of lost connections: WebSocket ping/pong. 是的,有一个更好的解决方案可以快速检测丢失的连接:WebSocket ping / pong。 This is built into the WebSocket protocol.
这是内置于WebSocket协议中的。
AutobahnPython supports automatic WebSocket Ping/Pong , mostly for exact this scenario (fast connection loss detection and connection keep-alive). AutobahnPython支持自动WebSocket Ping / Pong ,主要用于此情况(快速连接丢失检测和连接保持活动)。
You can activate this using these parameters: 您可以使用以下参数激活它:
autoPingInterval
autoPingTimeout
autoPingSize
which can be set for both servers and clients . 可以同时为服务器和客户端设置 。
You will need a recent AutobahnPython version (0.9.4+ I think). 您将需要一个最新的AutobahnPython版本(我认为是0.9.4+)。 Yours (0.6.5) does not have that feature.
您的(0.6.5)没有该功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.