简体   繁体   中英

Sockjs - Send message to sockjs-tornado in Python code

I use https://github.com/mrjoes/sockjs-tornado for a Django app. I can send messages from javascript console very easy. But I want to create a signal in Django and send json string once the signal is active.

Could anyone give me a way to send a certain message in Python to sockjs-tornado socket server?

There are few options how to handle it:

  1. Create simple REST API in your Tornado server and post your updates from Django using this API;
  2. Use Redis. Tornado can subscribe to the update key and Django can publish updates to this key when something happens;
  3. Use ZeroMQ (AMQP, etc) to send updates from the Django to the Tornado backend (variation of the 1 and 2).

In most of the cases, it is either first or second option. Some people prefer using 3rd option though.

I've wrote djazator , simple and easy to use django plugin. It uses zeromq for delivering messages from django to sockjs-tornado. Additionally, it can send messages to subset of authenticated django users.

我只是把它放在https://github.com/amagee/sockjs-client上,用于直接与Python的SockJS服务器通信(使用xhr流)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM