Created
December 6, 2011 12:24
-
-
Save ferblape/1438024 to your computer and use it in GitHub Desktop.
Actuable Websockets using Node.JS
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 cluster = require('cluster'); | |
if (cluster.isMaster) { | |
for (var i = 0; i < 3; i++) { | |
cluster.fork(); | |
} | |
cluster.on('death', function(worker) { | |
console.log('worker ' + worker.pid + ' died'); | |
}); | |
} else { | |
var http = require('http'), | |
redis = require("redis"), | |
client = redis.createClient("6379", "192.168.152.171"); | |
client.setMaxListeners(0); | |
var io = require('socket.io').listen(3001); | |
var connected_socket; | |
io.set('log level', 1); | |
io.sockets.on('connection', function (socket) { | |
client.on("message", function (channel, message) { | |
var parsed_message = JSON.parse(message); | |
socket.emit(parsed_message['id'], message); | |
if(parsed_message['type'] == "update_signatures"){ | |
socket.emit("update_signatures_message", message); | |
} | |
}); | |
}); | |
client.subscribe("actuable-realtime"); | |
} |
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" : "actuable-rt", | |
"author" : "Fernando Blat <[email protected]>", | |
"version" : "0.1.0", | |
"dependencies": { | |
"hiredis" : ">= 0.1.x", | |
"redis" : ">= 0.7.x", | |
"socket.io" : ">= 0.8.x", | |
}, | |
"engine": "node >= 0.6.6" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment