Created
May 30, 2012 22:10
-
-
Save myndzi/2839254 to your computer and use it in GitHub Desktop.
(not!) Uncatchable socket errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'), | |
net = require('net'); | |
try { | |
var req = http.request({ | |
host: '127.0.0.1', | |
port: 18602, | |
'createConnection': | |
function (port, host) { | |
var s = new net.Socket(); | |
// this is every event emitted in lib/net.js | |
s.on('error', function (err) { console.log('Socket.error: ', err); }); | |
s.on('timeout', function () { console.log('Socket.timeout'); }); // why this isn't 'error' is anybody's guess | |
s.on('end', function () { console.log('Socket.end'); }); | |
s.on('close', function () { console.log('Socket.close'); }); | |
s.on('connect', function () { console.log('Socket.connect'); }); // for completeness's sake | |
s.on('connection', function () { console.log('Socket.connection'); }); // ditto | |
s.on('drain', function () { console.log('Socket.drain'); }); // ditto | |
s.on('listening', function () { console.log('Socket.listening'); }); // ditto | |
s.on('data', function () { console.log('Socket.data'); }); // ditto | |
// from http | |
s.on('agentRemove', function () { console.log('Socket.agentRemove'); }); | |
return s.connect(port, host); | |
} | |
} | |
); | |
req.setTimeout(5000); | |
req.on('error', function (err) { console.log('http.error: ', err); }); | |
req.on('clientError', function (err) { console.log('http.clientError: ', err); }); | |
req.on('checkContinue', function () { console.log('http.checkContinue'); }); | |
req.on('data', function () { console.log('http.data'); }); | |
req.on('end', function () { console.log('http.end'); }); | |
req.on('close', function () { console.log('http.close'); }); | |
req.on('drain', function () { console.log('http.drain'); }); | |
req.on('request', function () { console.log('http.request'); }); | |
req.on('timeout', function () { console.log('http.timeout'); }); | |
req.on('connect', function () { console.log('http.connect'); }); | |
req.on('socket', function () { console.log('http.socket'); }); | |
req.on('continue', function () { console.log('http.continue'); }); | |
req.on('upgrade', function () { console.log('http.upgrade'); }); | |
req.on('response', function () { console.log('http.response'); }); | |
req.on('aborted', function () { console.log('http.aborted'); }); | |
req.on('free', function () { console.log('http.free'); }); | |
req.on('finish', function () { console.log('http.finish'); }); | |
req.on('drain', function () { console.log('http.drain'); }); | |
} catch (e) { | |
console.log('caught: ', e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment