Node.js,Socket.io,Http-Proxy,Cluster,Express - Handshake drops on disconnect - delay in reconnect -


i'm using node.js , socket.io. i'm using http-proxy use port 80 on machine that's running apache also. apache on different ip. works great.

i added in cluster , things got funky. spawns 2 workers (dual core vm) expected. connection on client side, off. it's good, if disconnect, there's delay reconnecting (there wasn't without cluster).

here's code have.. ideas why there's delay between disconnect , connect using cluster?

var http          = require('http'),     httpproxy     = require('http-proxy'),     io            = require('socket.io'),     cluster       = require('cluster'),     express       = require('express'),     redisstore    = require('connect-redis')(express);   var numcpus = require('os').cpus().length;  if (cluster.ismaster) {        //fork workers.       (var = 0; < numcpus; i++) {         cluster.fork();       }        cluster.on('death', function(worker) {         console.log('worker ' + worker.pid + ' died');       });  } else {       //server workers     var app = express.createserver().listen(8585, '172.16.183.129');     app.configure(function(){           app.use(express.bodyparser());           app.use(express.methodoverride());           app.use(express.cookieparser());           app.use(express.session({ secret: "secret", store: new redisstore}));           app.use(app.router);           app.use(express.errorhandler({showstack: false, dumpexceptions: false}));           app.use(express.static(__dirname + '/public'));     });       //create proxy server use port 80     var proxy = httpproxy.createserver(8585, '172.16.183.129');     proxy.listen(80, '172.16.183.129');      //initilize socket.io     var io = require('socket.io').listen(app, {origins: '*:*'});           io.sockets.on('connection', function(socket){             var test = setinterval(function() {               socket.emit('test', { result: numcpus});                i++;           }, 900);             socket.on('disconnect', function () {                 console.log('disconnect');                 clearinterval(auctiontimer);             });            });  } 

you need add in redisstore socket workers can work together. note latest version of socket.io has built in redisstore should use instead of connect-redis stuff.

socketio = require('socket.io')  var io = socketio.listen(app, {origins: '*:*'});   var host = 'redisserver' var opts = {redissub:{host:host},redispub:{host:host},redisclient:{host:host}} io.set('store', new socketio.redisstore(opts)) 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -