Skip to content

Instantly share code, notes, and snippets.

@koichik
Created May 2, 2012 09:33
Show Gist options
  • Select an option

  • Save koichik/2575536 to your computer and use it in GitHub Desktop.

Select an option

Save koichik/2575536 to your computer and use it in GitHub Desktop.

Revisions

  1. koichik created this gist May 2, 2012.
    24 changes: 24 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    var net = require('net');
    var http = require('http');

    var server = net.createServer(function(socket) {
    socket.write('HTTP/1.1 204 No Content\r\n\r\nNo Content');
    }).listen(3000, function() {
    var req = http.get({port: 3000}, function(res) {
    console.log('got response', res.statusCode);
    res.on('end', function() {
    console.log('end response');
    });
    res.on('error', function(err) {
    console.log('could not catch here, because this response is ended', err);
    });
    });
    req.on('error', function(err) {
    console.log('could not catch here, because this request is ended', err);
    });
    });

    process.on('uncaughtException', function(err) {
    console.log('we can catch error here', err);
    server.close();
    });