使用域时,node.js套接字没有响应

我按照课本的例子input,但没有客户的回应。 它假设通过域方法popup一些错误信息,但没有发生。

server.js:

var http = require('http'); var domain = require('domain'); http.createServer(function (req, res) { var reqd = domain.create(); reqd.add(req); reqd.add(res); reqd.on('error', function (err) { res.writeHead(200); res.write('server got error when responsing to client request '); res.end(err.message); }); res.writeHead(200); res.on('data', function () { nonexist(); res.write('hello'); res.end(); }); }).listen(1337); 

client.js

 var http = require('http'); var options = { hostname: 'localhost', port: 1337, path: '/', method: 'POST', }; var req = http.request(options, function (res) { res.setEncoding('utf-8'); res.on('data', function (chunk) { console.log('response content: ' + chunk); }); }); req.write('hello'); req.end('byebye');