Skip to content

Instantly share code, notes, and snippets.

@lpinca
Last active November 30, 2015 09:20
Show Gist options
  • Save lpinca/bf2c318d655ea8b75981 to your computer and use it in GitHub Desktop.
Save lpinca/bf2c318d655ea8b75981 to your computer and use it in GitHub Desktop.
Primus GH-398
'use strict';
const eio = require('engine.io-client');
new eio('http://localhost:3000/');
{
"name": "gh-398",
"version": "0.0.0",
"description": "",
"dependencies": {
"engine.io": "^1.6.1",
"engine.io-client": "^1.6.1"
},
"scripts": {
"start": "node server.js"
},
"author": "",
"license": "MIT"
}
'use strict';
const fork = require('child_process').fork;
const eio = require('engine.io');
const http = require('http');
const server = http.createServer();
const io = eio.attach(server);
let count = 0;
let client;
io.on('connection', socket => {
count++;
console.log('%s connected, count %s', socket.id, count);
client.kill();
socket.on('close', () => {
count--;
console.log('%s disconnected, count %s', socket.id, count);
});
});
server.listen(3000, function createClient() {
client = fork(__dirname + '/client.js');
client.on('close', createClient);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment