1

I would like to periodically update the data sent to all the connected clients, over the socket.io connection, does socket.io have a function or feature for doing this?

OzzieSpin
  • 45
  • 7
  • socket.io do not have this feature. You can do it manually by setting timer function and simple socket.io.emit. – Dmitry Apr 17 '16 at 13:17

2 Answers2

0

Yes, you can simply

var io = require('socket.io')();
io.sockets.emit('an event for everybody', { some: 'data' });

If you're not calling this on a specific connection it will broadcast to all connected clients.

Julien
  • 9,312
  • 10
  • 63
  • 86
0

Generally, you don't need to worry about synchronising data with Socket.io. Simply because it's bi-directional & event-based. But you still can update stream from server or client side based on events.

Take a look at this article

To make the update periodic (based on time), you can use setTimeout() function in Javascript. More on that in this question

Community
  • 1
  • 1
Garsallah mohamed
  • 156
  • 1
  • 1
  • 10