简体   繁体   English

自动更新套接字连接数据? socket.io

[英]Automatically updating a socket connections data? socket.io

我想定期更新发送到所有连接客户端的数据,通过socket.io连接,socket.io是否具有执行此操作的功能或功能?

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. 如果您没有在特定连接上调用它,它将广播到所有连接的客户端。

Generally, you don't need to worry about synchronising data with Socket.io. 通常,您不必担心与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. 要定期更新(基于时间),可以在Javascript中使用setTimeout()函数。 More on that in this question 更多关于这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM