Skip to content

Instantly share code, notes, and snippets.

@developerdizzle
Last active August 29, 2015 14:07
Show Gist options
  • Save developerdizzle/28a881d4edc57a21b6c7 to your computer and use it in GitHub Desktop.
Save developerdizzle/28a881d4edc57a21b6c7 to your computer and use it in GitHub Desktop.
Primus WS Reconnect server
/* server.js */
//
// # SimpleServer
//
// A simple chat server using Socket.IO, Express, and Async.
//
var http = require('http');
var path = require('path');
var Primus = require('primus');
var express = require('express');
//
// ## SimpleServer `SimpleServer(obj)`
//
// Creates a new instance of SimpleServer with the following options:
// * `port` - The HTTP port to listen on. If `process.env.PORT` is set, _it overrides this value_.
//
var router = express();
var server = http.createServer(router);
var primus = new Primus(server);
primus.library();
primus.save(__dirname + '/client/js/primus.js');
router.use(express.static(path.resolve(__dirname, 'client')));
primus.on('connection', function(spark) {
console.log('new connection');
setTimeout(function() {
console.log('destroying');
process.exit(1);
}, 10000)
});
server.listen(process.env.PORT || 3000, process.env.IP || "0.0.0.0");
/* Forever command */
/* forever --minUptime 604800000 --spinSleepTime 15000 start server.js */
@3rd-Eden
Copy link

The issue is caused by Cloud9 as they don't close down the WebSocket connection when your application is not running. It just simply accepts the connection and does nothing with it. But this problem did show an interesting problem with our reconnection logic, which has been reported at: primus/primus#297

Thanks again for taking the time to join us on IRC and providing us with a reproducible testing environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment