我这里有个小问题:
前段时间我使用 PHP 代码实现了 HTTP 流,类似于此页面上的内容:
http://my.opera.com/WebApplications/blog/show.dml/438711#comments
我用非常相似的解决方案获得数据。现在我尝试使用此页面中的第二个代码(在 Python 中),但无论我做什么,在一切完成后,我都会从 python 服务器收到 responseText。下面是一些python代码:
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)
这是Javascript代码:
ask = new XMLHttpRequest();
ask.open("GET","/Chat",true);
setInterval(function()
{
if (ask.responseText) document.write(ask.responseText);
},200);
ask.send(null);
有人知道我做错了什么吗?我怎样才能一个接一个地收到那些该死的消息,而不仅仅是在while循环结束时收到所有消息?感谢您在这里的任何帮助!
编辑:
我忘记添加的主要内容:服务器是谷歌应用服务器(我不确定谷歌自己的实现),这是一个带有一些解释的链接(我认为嗯):
http://code.google.com/intl/pl-PL/appengine/docs/python/gettingstarted/devenvironment.html http://code.google.com/intl/pl-PL/appengine/docs/whatisgoogleappengine.html