Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.