Is there any way to use Socket.IO http://socket.io/ with Django?
相关问题
- Multiple sockets for clients to connect to
- Django __str__ returned non-string (type NoneType)
- Django & Amazon SES SMTP. Cannot send email
- Django check user group permissions
- Django restrict pages to certain users
相关文章
- Profiling Django with PyCharm
- Why doesn't Django enforce my unique_together
- MultiValueDictKeyError in Django admin
- Django/Heroku: FATAL: too many connections for rol
- Django is sooo slow? errno 32 broken pipe? dcramer
- File Upload of more than 4GB
- Django: Replacement for the default ManyToMany Wid
- Upgrading transaction.commit_manually() to Django
Sure you can!
Django itself arent asyncronous so you have to use a Socket.IO server in parallel with your normal django server, node.js isnt always a good choice but there exists others written in pure python.
here is a blog/tutorial that uses gevent as socket.io server.
http://codysoyland.com/2011/feb/6/evented-django-part-one-socketio-and-gevent/
For a similar solution that has a bit more history you can look at Orbited, (www.orbited.org)
Guys there is no solid support for socket.io with django... there is how ever easy toy program support g-event socket.io support was dropped for the last year as well, django-socket.io is also abandoned. If you want to build a simple toy program using django-socket.io and or g-event socket.io sure, but anything that scales is unlikely "https://github.com/ryesoft/gevent-socketio" this is experimental.
Issues with more than 1 worker with gunicorn.... https://github.com/abourget/gevent-socketio/issues/112
The work around is this commit. https://github.com/getpenelope/gevent-socketio/commit/6c80c17705c9a1b3adcb0f99abde1c4d369c337b
I thought it would throw it out there just incase someone was trying to use this in a production environment like my self.
I think the best way to asyncronous communication with Django is have a node server listening in another port and use the api client of Socket.io. In this way, you aren't depend of the support of the modules for django and is very simple: Node listening the request from client, convert this request in a post request and send to Django for the port which listen Django. Is the best way i think.
server.js
views.py
index.html
Start here:
and here:
There are some Django examples as to how to get started.
It is based on Gevent, which implements a cooperative concurrency model. It's great coming from a request/response world, as it adds some callbacks and micro-threads without imposing it massively on your workflow.
Try it out :)
No. node.js is its own language running in its own interpreter. However if you are asking if there is a Django app which allows communicating with a Socket.IO client, then yes and no. No because no pre-made solution currently exists, and yes because all the parts you need to implement it already exist.
To implement the protocol with django, check out Django-Websocket for the backend websocket server, Ajax libraries from Dajax Project and Socket.IO-rack which is a ruby gem which implements the protocol and ruby is close enough in structure to django that you can get a lot of inspiration from it.
For an example of using socket.io with django, you might want to look at django-serverpush. It integrates django with socket.io as the transport and tornado/tornandio2 as the async server instead of node.js
https://github.com/hamax/django-serverpush
Other have used django with node.js+socket.io with rabbitMQ as the message queue bridge between the two. There was a talk, "Real-Time Django" at djangocon 2011 which described usng this approach for large real-time (award-show-type) applications.