I'm using autobahn to run a websocket server to complement my Django app. Sometimes, I need to send messages from Django to the websocket server, which works fine using the websocket-client module. I would love to use the WAMP protocol instead because the RPC/PubSub API looks great, but the python client code is implemented as a twisted protocol, and I can't figure out how to use that imperatively, i.e. like a function call and not from some foreign event loop. Is there anything I'm not seeing in the docs, or should my architecture be different?
Asked
Active
Viewed 1,464 times
5
-
2Everything in Python is imperative. I think you mean "blockingly" or maybe "synchronously". – Jean-Paul Calderone May 20 '13 at 11:59
-
Regarding architecture, there are (at least) 2 options: a) run Autobahn as a separate server and access that as a client from Django. b) run Django and Autobahn (server) within 1 process. There is an example for doing b) with Flask and Autobahn here https://github.com/tavendo/AutobahnPython/blob/master/examples/websocket/echo_wsgi/server.py – oberstet May 20 '13 at 13:33
-
@Jean-PaulCalderone: You're right, I want a synchronous, blocking call. – Simon May 20 '13 at 14:38
-
1@oberstet: I do a) and the "access that as a client from Django" part is what I'm interested in. I can do it for a plain websocket server using a third-party module, but I don't know how to do a WAMP RPC call, e.g. from a Django view function. – Simon May 20 '13 at 14:40
-
@Simon a) is also what I'm looking for, but I'm wondering if making synchronous call to Twisted would not be a anti-pattern. That said, I don't know yet how to do it in another way. – Andre Miras Jun 24 '14 at 09:54
1 Answers
5
https://github.com/itamarst/crochet might help you out with this.

Jean-Paul Calderone
- 47,755
- 6
- 94
- 122
-
Interesting. And yeah, using this lib it seems you could do what you want: run Autobahn (client) within your app, but blocking (from your app POV). – oberstet May 20 '13 at 17:43
-
Isn't it possible to just instantiate and use the WAMP client without running an event loop? Or would that require creating a full-blown "eventloop-less" implementation in addition to the Twisted & asyncio implementations? – Petri Sep 22 '15 at 06:53