Javascript – Google Apps HTTP Streaming with Python question

javascriptpythonstreaming

I got a little question here:

Some time ago I implemented HTTP Streaming using PHP code, something similar to what is on this page:

http://my.opera.com/WebApplications/blog/show.dml/438711#comments

And I get data with very similar solution. Now I tried to use second code from this page (in Python), but no matter what I do, I receive responseText from python server after everything completes. Here are some python code:

print "Content-Type: application/x-www-form-urlencoded\n\n"

i=1
while i<4:
 print("Event: server-time<br>")
 print("data: %f<br>" % (time.time(),))
 sys.stdout.flush()
 i=i+1
 time.sleep(1)

And here is Javascript Code:

ask = new XMLHttpRequest();
ask.open("GET","/Chat",true);
setInterval(function()
{
if (ask.responseText) document.write(ask.responseText);
},200);
ask.send(null);

Anyone got idea what I do wrong ? How can I receive those damn messages one after another, not just all of them at the end of while loop? Thanks for any help here!

Edit:

Main thing I forgot to add: server is google app server (i'm not sure is that google own implementation), here is a link with some explanation (i think uhh):

http://code.google.com/intl/pl-PL/appengine/docs/python/gettingstarted/devenvironment.html
http://code.google.com/intl/pl-PL/appengine/docs/whatisgoogleappengine.html

Best Solution

Its highly likely App Engine buffers output. A quick search found this: http://code.google.com/appengine/docs/python/tools/webapp/buildingtheresponse.html

The out stream buffers all output in memory, then sends the final output when the handler exits. webapp does not support streaming data to the client.

Related Question