Not getting message in console
Hi,
I have followed the readme as it is , but not getting any message on my developer console after binging up the server and sending publish pong 'o:{"a":123, "b":456}' from redis-cli
Code added in broker.js
var scRedis = require('sc-redis');
module.exports.run = function (broker) { console.log(' >> Broker PID:', process.pid); scRedis.attach(broker); };
Code added in server.js
var argv = require('minimist')(process.argv.slice(2)); var SocketCluster = require('socketcluster').SocketCluster;
var socketCluster = new SocketCluster({ workers: Number(argv.w) || 1, brokers: Number(argv.b) || 1, port: Number(argv.p) || 8000, authKey: 'todo', appName: argv.n || null, workerController: __dirname + '/worker.js', brokerController: __dirname + '/broker.js', socketChannelLimit: 100, rebootWorkerOnCrash: argv['auto-reboot'] != false, pingTimeout: 5000, pingInterval: 2000, brokerOptions: { host : '172.16.11.155', port: 6379 } });
I had the same issue. Just add the following code to your frontend application:
var socket = socketCluster.connect();
// ...
var pongChannel = socket.subscribe('pong');
pongChannel.on('subscribeFail', function (err) {
console.log('Failed to subscribe to the pong channel due to error: ' + err);
});
pongChannel.watch(function (data) {
console.log('Pong channel message:', data);
});
The readme says: Open your browser window and connect to your SC server... By default it's at: http://localhost:8000/ - Then open the developer console. Note that your client will subscribe to a 'pong' channel on SocketCluster. SC-Redis will automatically handle all the synchronization work.