Last active
December 11, 2015 18:09
-
-
Save jmyrland/4639758 to your computer and use it in GitHub Desktop.
socket.io xhr-polling test.
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 i = 0, | |
io = require('socket.io'), | |
http = require('http'); | |
var server = http.createServer().listen(80); | |
io = io.listen(server); | |
io.set('transports', [ 'xhr-polling' ]); | |
io.sockets.on('connection', function(socket){ | |
i++; | |
socket.log.info('Client ' + i + ' connected.'); | |
}); |
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 io = require("socket.io-client") | |
var connectionInterval = 500; | |
var numberOfUsersToConnect = 100; | |
var connections = 0; | |
var connectionTimestampSum = 0; | |
var options = { | |
transports: ['xhr-polling'], | |
'force new connection': true | |
}; | |
// UPDATE: This fixes the problem! | |
var http = require('http'); | |
http.globalAgent.maxSockets = 100; | |
http.Agent.maxSockets = 100; | |
for (var i = 1; i <= numberOfUsersToConnect; i++) { | |
(function (index) { | |
setTimeout(function () { | |
console.log(index + "/" + numberOfUsersToConnect + " tries to connect!"); | |
var time = Date.now(), | |
socket = io.connect("http://localhost", options) | |
socket.on('connect', function () { | |
connections++; | |
connectionTimestampSum += Date.now() - time; | |
console.log((connections) + "/" + numberOfUsersToConnect + " connected! (" + (Date.now() - time )+ "ms)"); | |
if (connections == numberOfUsersToConnect) { | |
console.log("Average connect time: " + Math.round(connectionTimestampSum / connections) + " ms!"); | |
console.log(""); | |
} | |
}); | |
}, index * connectionInterval); | |
})(i); | |
} |
How can I use require command on the browser ? I am getting require is not defined error.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related to socketio/socket.io#1145