Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
socket.io problem
var io = require('socket.io').listen(8090,{"destroy upgrade": false})
, fs = require('fs')
, redis = require('redis');
var client = redis.createClient(6379,'localhost');
redis.debug_mode = true;
client.subscribe("football.match.event");
io.enable('browser client minification');
client.on("error", function (err) {
console.log("error event - " + client.host + ":" + client.port + " - " + err);
console.log('connected: ' + client.connected);
});
client.on("end", function (err) {
console.log("error event - " + client.host + ":" + client.port + " - " + err);
});
client.on("close", function (err) {
console.log("error event - " + client.host + ":" + client.port + " - " + err);
});
var socket = io.sockets.on('connection', function (socket) {
console.log("connection");
doMessageListen(socket);
});
var socket = io.sockets.on('reconnect', function (socket) {
console.log('reconnection');
doMessageListen(socket);
});
client.on("message", function (channel, message) {
console.log("client1 channel " + channel + ": " + message);
});
var doMessageListen = function(socket) {
return client.on("message", function(channel, message) {
console.log('received message: ' + message);
// if the message doesn't parse as JSON then the client throws an Error
// The on error handler above is call and I no longer receive any client messages
socket.json.emit('score',JSON.parse(message));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment