Created
March 9, 2016 20:04
-
-
Save Acconut/ccbf22ea97e1f0f783bb 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"); | |
var http = require("http"); | |
if(cluster.isMaster) { | |
cluster.fork(); | |
cluster.fork(); | |
testConnection(); | |
setInterval(testConnection, 1000); | |
} else { | |
var server = http.createServer(function(req, res) { | |
process.stdout.write(cluster.worker.id.toString()); | |
res.writeHeader(202); | |
res.end(); | |
setTimeout(function() { | |
server.listen(7070); | |
}, 2000); | |
server.close(); | |
}); | |
server.listen(7070); | |
} | |
function testConnection() { | |
http.get("http://localhost:7070/", function(res) { | |
printStatus(res.statusCode == 202); | |
}).on("error", function() { | |
printStatus(false); | |
}); | |
} | |
function printStatus(success) { | |
if(success) { | |
process.stdout.write("."); | |
} else { | |
process.stdout.write("!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment