Created
August 8, 2012 09:54
-
-
Save paulgrav/3293884 to your computer and use it in GitHub Desktop.
socket.io problem
This file contains hidden or 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 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