In Socket.IO, is 'heartbeat' an event that can be used to trigger other actions?

北城以北 提交于 2019-12-03 03:03:55

I think that I see what you're trying to do. There are a few exposed events that you can check here - list of Socket.io events - but there is no "heartbeat" event that you can tap into to fire at a set interval.

You're on the right track with the second piece of code -

setInterval(function() {
    socket.emit('heartbeat', someData);
}, 5000);

And on the client side -

socket.on('heartbeat', function(data) {
    console.log(data);
})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!