Created
August 25, 2011 05:14
-
-
Save yssk22r/1170024 to your computer and use it in GitHub Desktop.
Node http timeout
This file contains 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
#!/usr/bin/env node | |
var http = require('http'); | |
var server = http.createServer(function(req, res){ | |
}).listen(8080, function(){ | |
// a('api.vcap.me'); | |
a('localhost', 8080); | |
}); | |
function a(host, port){ | |
var req = http.get({ | |
host: host, | |
port: port || 80, | |
path: '/' | |
}); | |
req.on('response', function(res){ | |
console.log('res'); | |
}); | |
req.socket.setTimeout(1000, function(){ | |
req.socket.destroy(); | |
console.log('timeout'); | |
}); | |
req.on('error', function(e){ | |
console.log(e); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment