3

I have tornado application, that serves websockets connections, and Django app. I want to share open websockets between Django and Tornado (i.e. write to sockets from Django application). What is the easiest way to achieve this?

Vladimir Mihailenco
  • 3,382
  • 2
  • 24
  • 38
  • Just to be clear, is this about using websockets as a communication channel between Tornado and WebSockets? – Seanny123 Oct 09 '14 at 21:26

1 Answers1

1

Easiest way to do it is to use a tornado.wsgi.WSGIContainer wrapping a django.core.handlers.wsgi.WSGIHandler. There is a good example at http://djangosnippets.org/snippets/1748/.

Zhehao Mao
  • 1,789
  • 13
  • 13
  • Do websockets work under WSGI? I was under the impression that nothing asynchronous would work. – Cole Maclean Jun 27 '11 at 16:41
  • Hmm, according to their documentation it does not support asynchronous. Perhaps use one of the other tornado handlers and call the Django app with that. – Zhehao Mao Jun 27 '11 at 17:21
  • Google search for "tornado and django" reveals the following http://lincolnloop.com/blog/2009/sep/15/using-django-inside-tornado-web-server/. Not sure how good it is. – Zhehao Mao Jun 27 '11 at 18:31
  • No, wait a minute, I've got it http://djangosnippets.org/snippets/1748/ says use tornado's WSGIContainer. I'm editing my post. – Zhehao Mao Jun 27 '11 at 18:35
  • Why not simply use django-websockets in such case? Currently I ended up with sending messages to tornado app via rabbitmq and consuming them in child thread. – Vladimir Mihailenco Jun 27 '11 at 20:18
  • The author of django-websockets gives a long explanation of some of the problems here: http://stackoverflow.com/questions/4363899/making-moves-w-websockets-and-python-django-twisted Basically, WSGI is limiting. Your solution seems like it would be OK. – Cole Maclean Jun 27 '11 at 20:36