Created
April 11, 2012 23:43
-
-
Save kapouer/2363512 to your computer and use it in GitHub Desktop.
Gently launch clients one after another, against a simple server.
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 Socket = require('engine.io-client').Socket; | |
var count = 0; | |
var opened = 0; | |
var MAX = 10; | |
initClient(); | |
function initClient() { | |
var conn = new Socket({ | |
host: 'localhost' | |
, port: 8007 | |
}); | |
conn.on('error', function(e) { | |
console.log(e); | |
}); | |
conn.on('open', function() { | |
console.log('opened', opened++); | |
if (opened <= MAX) process.nextTick(initClient); | |
conn.on('message', function() { | |
console.log('received', count++); | |
}); | |
conn.on('close', function(e) { | |
console.log('close', e); | |
}); | |
}); | |
} |
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
dev:~/tmp/wstests$ node test.js | |
opened 0 | |
opened 1 | |
received 0 | |
received 1 | |
opened 2 | |
opened 3 | |
received 2 | |
opened 4 | |
received 3 | |
opened 5 | |
opened 6 | |
opened 7 | |
received 4 | |
received 5 | |
dev:~/tmp/wstests$ |
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 engine = require('engine.io') | |
, server = engine.listen(8007) | |
server.on('connection', function (socket) { | |
socket.send('utf 8 string'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment