[Python] Autobahn: catch sendMessage error

Discussão em 'Python' iniciado por Stack, Julho 11, 2025.

  1. Stack

    Stack Membro Participativo

    how can I catch sendMessage error ? 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.

    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

    Continue reading...

Compartilhe esta Página