Last active
November 30, 2015 09:20
-
-
Save lpinca/bf2c318d655ea8b75981 to your computer and use it in GitHub Desktop.
Primus GH-398
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
'use strict'; | |
const eio = require('engine.io-client'); | |
new eio('http://localhost:3000/'); |
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
{ | |
"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" | |
} |
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
'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