[Django]-Django + Coffescript: Real time video application with io sockets

2👍

I’d recommend using a non-django service to handle the websockets. Setting up websockets properly is tricky on both the client and server side. Look at pusher.com for a free/cheap solution that will just work and save you a whole lot of hassle.

The initial request to start rendering should kick off the long-lived process, and return with an ID which is used to listen to the websocket for updates.

Once you have your websockets set up, you can send messages to the client about each finished frame. Personally I wouldn’t try to push the whole frame down the websocket, but rather just send a message saying the frame is done with a URL to get the frame. Then normal HTTP with its caching and browser niceties moves the big data.

You’re definitely not choosing the easy path. The easy path is to have your long-lived render task update the render state in the database, and have the client poll that. Extra server load, but a lot simpler.

👤Leopd

1👍

Django itself really is focused on doing one kind of web interface, which is following the HTTP Request/Response pattern. To maintain a persistent connection with clients, which socket.io really makes dead simple, you need to diverge a bit from a normal Django installation.

  1. This article discusses the issue of doing real-time with Django, with the help of Orbited and Twisted. It’s rather old, and it relies on Comet, which is not the preferred way of doing real-time these days.

  2. You might benefit a lot by going for Socket.io on the client, and something like Tornado (wiki) + Tornado client for Socket.io. But, if you really want to stick with Django for the web development (which Tornado also provide), you would need to make the two work together internally, each handling their particular use case.

  3. Finally, this other article discusses how to make Django work with gevent (an coroutine-based networking library for Python) and Socket.io, which might well be your best option otherwise.

Don’t hesitate to post questions/comments as they pop up!

Leave a comment