Skip to content

Instantly share code, notes, and snippets.

@einaros
Created March 1, 2012 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save einaros/18c03a9513c75e9c36a7 to your computer and use it in GitHub Desktop.
Save einaros/18c03a9513c75e9c36a7 to your computer and use it in GitHub Desktop.
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