Google Apps HTTP Streaming with Python question

By : Wilq32

I got a little question here:

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

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"

while i<4:
 print("Event: server-time<br>")
 print("data: %f<br>" % (time.time(),))

And here is Javascript Code:

ask = new XMLHttpRequest();"GET","/Chat",true);
if (ask.responseText) document.write(ask.responseText);

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!


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):

By : Wilq32


Its highly likely App Engine buffers output. A quick search found this:

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.

That looks like a cgi code - I imagine the web server buffers the response from the cgi handlers. So it's really a matter of picking the right tools and making the right configuration.

I suggest using a wsgi server and take advantage of the streaming support wsgi has.

Here's your sample code translated to a wsgi app:

def app(environ, start_response):
    start_response('200 OK', [('Content-type','application/x-www-form-urlencoded')])
    while i<4:
        yield "Event: server-time<br>"
        yield "data: %f<br>" % (time.time(),)

There are plenty of wsgi servers but here's an example with the reference one from python std lib:

from wsgiref.simple_server import make_server

httpd = make_server('', 8000, app)
By : ionelmc

You can also use scp to transfer entire directories from the shell prompt. For example:

MyMachine$ scp -r FromMachine:[Directory Path] [Destination Path]

This copies the entire directory and its contents to the destination path on MyMachine. Please see "man scp" for more information.

Users IMHO should be using sftp and ssh as FTP sends passwords as clear text.

This video can help you solving your question :)
By: admin