【问题标题】:How can I setup an Autobahn Pub/Sub Server and a Autobahn Webserver listening on the same port如何设置 Autobahn Pub/Sub Server 和 Autobahn Webserver 在同一个端口上侦听
【发布时间】:2013-04-26 10:38:37
【问题描述】:

我最近发现 autobahn python 和 js 是一种建立 pub/sub 服务器和相应客户端的舒适方法,即使使用 rpc 调用也是如此。

查看教程后,我设置了一个测试版本,其中一个 websocket 服务器和一个运行在同一端口上的 web 服务器。服务器通过 websocket 定期向客户端发送数据。用户获取的 html 位于 localhost 根目录上。一切正常。

但是,我想要完成的是:设置一个发布/订阅服务器和一个在同一个端口上侦听的网络服务器。

教程仅展示如何在两个不同的端口上设置这些(如http://autobahn.ws/python/tutorials/pubsub 所示)。

我对 python 和高速公路非常陌生,尤其是扭曲。 任何建议都会非常好!

非常感谢!

马克

【问题讨论】:

    标签: python websocket twisted publish-subscribe autobahn


    【解决方案1】:

    当然。您可以使用 Autobahn 在 one 端口上运行 WAMP/WebSocket 服务器普通的旧 Web 服务器。这是纯 WebSocket 的 examplehere 是 WAMP 的。

    免责声明:我是 Autobahn 的作者,为 Tavendo 工作。

    【讨论】:

    【解决方案2】:

    当在 HTTP 和 WS 服务器侦听同一端口时使用 WAMP 时,您需要按照 here 的说明手动启动 WampServerFactory 实例。

    factory = WampServerFactory("ws://localhost:8080")
    factory.protocol = YourServerProtocolClass
    factory.startFactory() # <--- need to call this manually
    resource = WebSocketResource(factory)
    root = File(".")
    root.putChild("ws", resource)
    

    更多详情请见this complete example

    【讨论】:

    • 自从 Autobahn 为 WAMPv2 更新后,该文件已移动 here
    【解决方案3】:

    我会将 nginx 作为前端,将每个调用转发到 pubsub 或 web...最近的 Nginx 支持 WebSocket 转发。

    或者你用 Twisted 写一些类似的东西:)

    另一种选择是将autobahn.websocket.WebSocketServerProtocol 及其子类autobahn.wamp.WampServerProtocol 改编为Twisted.web。 应该是可能的。

    【讨论】:

    • 感谢 monoid 的建议。我将浏览这些课程,看看我能取得什么成就。 Nginx 绝对是一种选择,但我更喜欢另一种方式:)。我仍然希望找到一个不错的解决方案,而不是重写高速公路类。使用twisted 和autobahn 可以在同一个端口上运行websocket 和webserver,所以也必须有一种方法可以使用pub/sub 来做到这一点:)
    猜你喜欢
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 2016-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-18
    • 1970-01-01
    相关资源
    最近更新 更多