I'm newbie to both node.js and socket.io but i want to write a small application to broadcast some values to connected clients. I don't know two thing first how can i fire socket.broadcast.emit or other broadcast functions in my other functions? in my app i have a function that calculate a value every second,and i want to send this value to all clients. my second question is how i get this message in clients and use it in my other javascript functions? i saw this before node.js + socket.io broadcast from server, rather than from a specific client? but failed to do what i want thanks in advance here is my code:
var cronJob = require('cron').CronJob;
var snmp = require('snmp-native');
//var oid = [1, 3, 6, 1, 2, 1, 1, 1, 0];
//var oid1 = [1,3,6,1,2,1,11,1];
//var oid2 = [1,3,6,1,4,1,2636,3,9,1,53,0,18];
//var oid3 = [1,3,6,1,2,1,2,2,1,11,18];
var intraffic = [1,3,6,1,2,1,2,2,1,10,18]; //inbound traffic
var outtraffic = [1,3,6,1,2,1,2,2,1,16,18]; //outbound traffic
var inpps = [1,3,6,1,4,1,2636,3,3,1,1,3,518]; //interface inbound pps
var outpps = [1,3,6,1,4,1,2636,3,3,1,1,6,518]; //interface out pps
var session = new snmp.Session({ host: '10.0.0.73', port: 161, community: 'Pluto@com' });
new cronJob('* * * * * *', function(){
session.get({ oid:intraffic }, function (error, varbind) {
var vb;
if (error) {
console.log('Fail :(');
} else {
vb=varbind[0];
console.log(vb.oid + ' = ' + vb.value + ' (' + vb.type + ')');
}
});
}, null, true, "America/Los_Angeles");