/** * Created with JetBrains WebStorm. * User: zhangyi * Date: 13-4-23 * Time: 上午10:57 * To change this template use File | Settings | File Templates. */var http = require('http');var sys = require('sys');var url = require("url");http.createServer(function(request, response) { response.writeHead(200, {"Content-Type" : "text/html"}); response.write(""); response.write(""); response.write(""); response.write("Progressive Loading"); for(var i = 0; i < 6; i++) { response.write(""); var down = 6; for (i = 0; i < 6; i++) { var proxy = http.createClient(2000, "localhost"); var proxyRequest = proxy.request("GET", "/?id=" + i, {"host" : "localhost"}); proxyRequest.addListener('response', function (proxyResponse) { --down; proxyResponse.addListener('data', function(chunk) { response.write(chunk, 'binary'); }); proxyResponse.addListener('end', function() { if(down == 0) { response.end(); } }); }); proxyRequest.end(); } response.write("");}).listen(8080);http.createServer(function(request, response) { var delay = Math.round(Math.random() * 8000); /* var params = url.parse(request.url, true); var delay = params.query.id * 3000; console.log(delay); */ setTimeout(function() { var params = url.parse(request.url, true); var id = params.query.id; response.writeHead(200, {"Content-Type" : "text/html"}); var content = "Content of Module " + id + ""; response.write(""); response.end(); }, delay);}).listen(2000);Loading..."); } response.write("
原文:http://www.cnblogs.com/meteoric_cry/archive/2013/04/23/3037384.html
posted on 2014-11-27 10:44 阅读( ...) 评论( ...)