Node-JS同时处理多个请求

时间:2015-03-23 13:22:50

标签: node.js request listener httpserver

我创建了一个侦听端口8888的服务器:

    http.createServer(function (req, res) {
        res.writeHead(200, {'Content-Type': 'text/html'});
        console.log('start server');

        req.on('data', function (data) {
            var 
                json = null,
                url_parts = {};

            url_parts = url.parse(req.url);
            json = JSON.parse(data);
            if (Router.route(url_parts, json, res) === false) {
                console.log('error with routing');
                res.end('error with routing');
                return;
            }
            console.log('end of request');
            res.end('success');
        });
    }).listen(8888);

Router.route中,执行的代码很重。

问题是 - 当有人访问网址http://localhost:8888/SOME_URL时,另一个对此端口的调用如:http://localhost:8888/SOME_OTHER_URL他必须等待很长时间..

如何同时处理这两个电话?

Tnx的帮助!

0 个答案:

没有答案
相关问题