Skip to content

Instantly share code, notes, and snippets.

@mixu
Created November 28, 2011 22:43
Show Gist options
  • Save mixu/1402427 to your computer and use it in GitHub Desktop.
Save mixu/1402427 to your computer and use it in GitHub Desktop.
Difference between OSX and Linux on Node 0.4.12
// Illustrates a difference in behavior between OSX and Linux
// (tested on OSX and Arch)
var http = require('http');
var server = http.createServer();
server.on('request', function (req, res) {
res.writeHead(200);
res.end('Hello world.');
});
server.listen(16000);
function makeRequest() {
var req = http.request({
host: 'localhost',
port: 16000,
path: '/'
}, function (res) {
var buf = '';
res.on('data', function (chunk) {
console.log('REQUEST CHUNK', chunk.toString());
buf += chunk;
});
res.on('end', function () {
console.log('END REQUEST', buf);
});
});
req.on('error', function (err) {
console.log(err);
throw err;
});
req.end();
}
// This works on OSX without process.nextTick()
// but fails on Linux with a Error: ECONNREFUSED, Connection refused
// Uncommenting delays the client request till nextTick(), which
// resolves the ECONNREFUSED
//process.nextTick(function() {
makeRequest();
//});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment