好,
我是node.js的新手.开始尝试,我正在关注Ryan Dahl(http://www.youtube.com/watch?v=jo_B4LTHi3I)的介绍,此时(大约0:17:00)有一个关于如何服务器的解释处理回应,
基本的例子是从webserver获得一个'hello'输出,然后在2秒之后出现'world',这段代码应该这样做
//Require the webserver library
var http = require('http');
var server = http.createServer(function(req, res) {
res.writeHead(200, { 'content-type' : 'text-plain' });
res.write('Hello\n');
//Asynchronous behavior
setTimeout(function() {
res.end('World\n');
}, 2000);
});
server.listen(3000);
Run Code Online (Sandbox Code Playgroud)
所以我运行它,我得到了Hello World,但是只有一个来自服务器的响应有完整的结果,即请求> 2秒>'Hello World'.而不是请求> Hello> 2秒>世界.
为什么?,我该如何改变这种行为?
我正在使用v0.8.18,curl -i http://localhost:3000返回正确的标题...
HTTP/1.1 200 OK
content-type: text-plain
Date: Sat, 26 Jan 2013 18:10:05 GMT
Connection: keep-alive
Transfer-Encoding: chunked