【问题标题】:Add an Autobahn websocket to a nested Twisted resource将 Autobahn websocket 添加到嵌套的 Twisted 资源
【发布时间】:2015-12-11 17:54:22
【问题描述】:

我有一个 Twisted 网络服务器,它同时为静态站点和高速公路网络套接字提供服务。 websocket 作为子节点添加到自定义站点,如下所示:

    self.factory = WebSocketServerFactory(address+":"+str(port), debug=False)
    self.factory.protocol = self.getWebSocketProtocol()

    resource = WebSocketResource(self.factory)

    staticfilepath = kwargs['staticfilepath'].encode('utf-8')
    websocketpath = kwargs['websocketpath'].encode('utf-8')
    root = CustomFile(staticfilepath)
    root.putChild(websocketpath, resource)

这工作正常。问题是我现在需要将 websocket 添加到嵌套路径(例如,而不是在websocketpath="ws" 使用websocketpath="sockets/ws")。我曾尝试拆分 websocketpath,然后为每个级别创建一个资源,将 websocket 添加到最终但它似乎不起作用。

【问题讨论】:

    标签: python websocket twisted autobahn


    【解决方案1】:

    我在 Twisted 中追踪到了 python 三字符串问题。如果输入的 url 带有斜杠,则一切正常。但是,如果没有尾部斜杠,则调用 Twisted 函数 addSlash,这会导致 Python 3 中出现未处理的异常。我对 Twisted 代码进行了修复,该代码与两个 python 版本都兼容并且似乎工作正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多