I want to create a web page to give the client news about his friends every 1 second using socket.io + node.js.
My codes are:
Customer:
var socket = io.connect('http://localhost:port'); socket.on('connect', function(){ socket.emit('hello', 'Hello guest'); }); socket.on('news_by_server', function(data){ alert(data); }); setInterval(function(){ socket.emit('news', 'I want news :D '); }, 1000);
server:
var io = require('socket.io').listen(port); io.sockets.on('connection', function (socket) { socket.on('hello', function(data){ console.log('new client connected'); }); socket.on('news', function(data){ socket.emit('news_by_server', 1); }); });
what are the network codes, but my question is INTERVAL, is it good to do news in real time or is there better than that.
source share