niwinz/django-sse

Long polling / streaming updates

Closed this issue · 5 comments

Having read your code, which is very nice otherwise, I notice a lack of yield statements which would be required to do long polling. Right now, it seems that the connection is closed after each response (whether a message is returned or not) - regardless of whether there's new data or not.

This leaves the major advantage of SSE unused. Especially for mobile devices creating TCP connections all the time can proof to be a considerable load. Also, it can slow down the interaction with the server.

Do note that I might have been misreading your code - haven't found the time to use it yet. Then again, I might opt to use your code in which I would implement the requested functionality myself.

Reference: http://stackoverflow.com/questions/2922874/how-to-stream-an-httpresponse-with-django

I think you're right. I'll experiment a bit, but I have understood that the connection is maintained at the level of tcp, not http. SSE performs GET requests each x time on a single connection tcp / ip (keep-alive). This with nginx 1.1.x and should work properly.

The specification says nothing about the long polling connection and stream (chunked).
Even so, I shall make some experiments, which can be an interesting solution.

HTTP runs over the TCP connection. Basically, what happends is the client makes one (1) connection to the server over which messages are routed in a streaming fashion. Only when a disconnect occurs is a new TCP-handshake (and consequently, HTTP request) necessary.

(Note: I have tested the fragment above for a experimental chat application and it worked fine. Could see if I could open source the app to share it with you - or I might just email you a Tarball instead.)

Lastly, refer to the introduction in http://www.html5rocks.com/en/tutorials/eventsource/basics/ where it pretty much starts with 'Long polling'. :)

I have already implemented stream. Try it ;)
Thanks for the idea.