我无法使用“applicationRunner”,因为它不支持 websockets 的自动重新连接(GitHub 问题:#295 #389)。我已经恢复到使用扭曲的“ReconnectingClientFactory”的已弃用方法。我的问题是这种方法似乎不允许我添加“ssl.optionsForClientTLS”来严格验证服务器主机名和证书。有没有办法做到这一点?
非常感谢任何反馈!
class MyClientFactory(websocket.WampWebSocketClientFactory, ReconnectingClientFactory):
maxDelay = config.maxretry
def clientConnectionFailed(self, connector, reason):
logging.debug("Connection Failed: %s", reason)
ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
def clientConnectionLost(self, connector, reason):
logging.debug("Connection Lost: %s", reason)
ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
def start():
log.startLogging(sys.stdout)
component_config = types.ComponentConfig()
session_factory = wamp.ApplicationSessionFactory(config=component_config)
session_factory.session = MyFrontendComponent
transport_factory = MyClientFactory(session_factory, 'wss://services:8443/ws', debug=True)
transport_factory.debug = True
transport_factory.debugCodePaths = True
websocket.connectWS(transport_factory)
Thread(target=reactor.run, args=(False,)).start()