Created
September 20, 2010 19:17
-
-
Save deanh/588474 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 http = require('http'); | |
var hitCnt = 0; | |
http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
hitCnt++; | |
console.log('Server 1: ' + hitCnt); | |
res.end('Server 1: ' + hitCnt + '\n'); | |
}).listen(8124, "127.0.0.1"); | |
console.log('Server running at http://127.0.0.1:8124/'); | |
http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
hitCnt++; | |
console.log('Server 2: ' + hitCnt); | |
res.end('Server 2: ' + hitCnt + '\n'); | |
}).listen(8125, "127.0.0.1"); | |
console.log('Server running at http://127.0.0.1:8125/'); | |
/* | |
output for one request to each of :8214 and :8125 | |
hitCnt is global and in scope for both servers: | |
dean@dean:~/Devel$ node node_try.js | |
Server running at http://127.0.0.1:8124/ | |
Server running at http://127.0.0.1:8125/ | |
Server 1: 1 | |
Server 1: 2 | |
Server 2: 3 | |
Server 2: 4 | |
note that the browser is hitting each server with two reqs, thusly pumping | |
the numbers. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment