-
-
Save einaros/18c03a9513c75e9c36a7 to your computer and use it in GitHub Desktop.
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
var cluster = require('cluster') | |
, http = require('http') | |
, net = require('net'); | |
if (cluster.isMaster) { | |
var srv = http.createServer(); | |
srv.on('upgrade', function(req, socket, upgradeHead) { | |
console.log('upgraded successfully'); | |
socket.end(); | |
}); | |
srv.listen(1337, '127.0.0.1', function() { | |
cluster.fork(); | |
}); | |
cluster.on('death', function() { srv.close(); }); | |
} | |
else { | |
var client = net.connect(1337, function() { | |
var lines = [ | |
'GET /demo HTTP/1.1', | |
'Upgrade: WebSocket', | |
'Connection: we love corndogs, and there are no upgrades here', | |
'Host: example.com' | |
]; | |
client.write(lines.concat(['', '']).join('\r\n')); | |
}); | |
client.on('end', function() { process.exit(); }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment