0

I have a websocket server using autobahn where it runs some code onMessage.

during this code an exception happens and I perform a try/except clause so I can log the error, it logs correctly. However the connection to the client(javascript) disconnects.

The problem is that if I load a new page it does not reconnect to the websocket server. I attempted to put the code block to start the server in a while loop but the client does not connect succesfully.

if __name__ == '__main__':

    import sys

    from twisted.python import log
    from twisted.internet import reactor, task, threads
    logging.basicConfig(filename='/var/log/myerror.log', level=logging.ERROR)

    log.startLogging(sys.stdout)

    factory = WebSocketServerFactory(u"ws://127.0.0.1:9000", debug=False)
    factory.protocol = MyServerProtocol
    factory.setProtocolOptions(maxConnections=50)

    reactor.listenTCP(9000, factory)
    reactor.run()

Does anyone know how to make it so even if the code in 'onMessage' has an exception, the websocket server will continue to accept connections and give other clients the opportunity to run?

user1601716
  • 1,893
  • 4
  • 24
  • 53

1 Answers1

0

Found the problem. I had placed 'reactor.callFromThread(reactor.stop) ' elsewhere in the code and it was killing the reactor.

user1601716
  • 1,893
  • 4
  • 24
  • 53