I am trying to use the Redis Cookbook example:
var http = require('http'), io = require('socket.io') fs = require('fs'), redis = require('redis'), rc = redis.createClient(9189, "pike.redistogo.com"); rc.auth("passwd", function() { console.log("Connected! to redistogo!");}); rc.on("connect", function() { rc.subscribe("chat"); console.log("rc connect event"); });
I succeed here, but never get a "message."
rc.on("message", function (channel, message) { console.log("Sending: " + message); socketio.sockets.emit('message', message); }); webpage = http.createServer(function(req, res){ console.log('webpage request starting...'); fs.readFile('./index.htm', function(error, content) { if (error) { res.writeHead(500); res.end(); } else { res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(content, 'utf-8'); } }); }); webpage.listen(7777);
my client side index.htm is
<!docttype html> <html lang="en"> <head> <script src ="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"> </script> <script src="http://www.heaphash.com:7777/socket.io/socket.io.js"></script> <script> var socket = io.connect('www.heaphash.com', { port: 7777}); socket.on('message', function(data){ var li = new Element('li').insert(data); $('messages').insert({top: li}); } </script> <meta charset="utf-8"> <title>Chat with Redis</title> </head> <body> <ul id="messages"> </ul> <form id="chatform" action=""> <input id="chattext" type="text" value="" /> <input type="submit" value="Send" /> </form> <script> $('#chatform').submit(function(){ socket.emit('message', $('chattext').val()); $('chattext').val(""); </script> </body> </html>
how a client publishes a specific Redis chat channel.
Charles Short Sep 18 '11 at 19:02 2011-09-18 19:02
source share