How to create loop to issue an event in socket.io?

7

I have an architecture problem.

I have a code using socket.io at nodejs :

socket.on('images',function (aData){
    ...
    socket.sockets.emit('show', JSON.stringify({imagens : json}))
});

I'm trying to broadcast a broadcast from time to time in the show event, but the connected sockets can not be sending the images event all the time.

A loop on the backend itself might resolve the issue, but I need a trigger for the images tails event other than the sockets connected.

Any solution or alternative?

    
asked by anonymous 20.01.2014 / 11:16

1 answer

4

Perhaps the setInterval () (English) help you through the use of an anonymous function:

var show = setInterval(function() {
    socket.sockets.emit('show', JSON.stringify({imagens : json}))
}, 10000);

The second argument refers to the time in milliseconds that the setInterval() function should wait between each call.

    
20.01.2014 / 23:13