3

I recently discovered autobahn python and js as a comfortable method to establish a pub/sub server and corresponding client even with rpc-calls.

After looking through the tutorials, I set up a test version with a websocket server and a webserver running on the same port. The server sends periodically data to the client via websockets. The html the user gets lies on the localhost root. All that works fine.

However, what I want to accomplish is: Setup a pub/sub server and a webserver listening on the same port.

The tutorials show only how to setup these on two different ports (as shown at http://autobahn.ws/python/tutorials/pubsub).

Im very new to python in general and autobahn and twisted especially. Any advice would be really nice!

Thanks very much!

Marc

user2323407
  • 103
  • 2
  • 7

3 Answers3

1

Sure. You can run a WAMP/WebSocket server and a plain old Web server on one port using Autobahn. Here is an example for pure WebSocket and here is one for WAMP.

Disclaimer: I am author of Autobahn and work for Tavendo.

oberstet
  • 21,353
  • 10
  • 64
  • 97
  • Hi Tobias Oberstein, would you please provide some additional information regarding this? Please see my newest answer were you can have a look into the source code. Thanks! – user2323407 May 02 '13 at 11:24
  • Examples can now be found here: https://github.com/tavendo/AutobahnPython/tree/master/examples – EmpireJones Aug 12 '14 at 03:47
1

When using WAMP while having HTTP and WS servers listening on the same port you will need to start your instance of WampServerFactory manually as explained here.

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

For more details please see this complete example.

tnajdek
  • 542
  • 5
  • 14
  • The file has moved [here](https://github.com/tavendo/AutobahnPython/blob/master/examples/twisted/wamp/app/keyvalue/store.py) since Autobahn updated for WAMPv2 – Bugster Dec 30 '14 at 22:16
0

I would put nginx as a frontend that forwards each call either to pubsub or to web... Recent Nginx supports WebSocket forwarding.

Or you man write something similar with Twisted :)

Another alternative would be to adapt autobahn.websocket.WebSocketServerProtocol and its subclass autobahn.wamp.WampServerProtocol to Twisted.web. It should be possible.

monoid
  • 1,661
  • 11
  • 16
  • Thank you monoid for your advice. I will look through the classes and see what I can achieve. Nginx is definitely an option, but I'd prefer the other way :). Im still hoping to find a nice solution instead of rewriting the autobahn classes. It is possible with twisted and autobahn to run websocket and webserver on same port, so there must be a way to do that with pub/sub, too :) – user2323407 Apr 29 '13 at 07:17