关于实施“存在”的建议对于一个网站?
理想情况下,我希望找到简单、轻量级的代码,允许连接到我的网站的所有 Web 客户端维护当前在线的其他人的实时状态。
我知道 ejabberd 可以做到这一点,但它还可以做很多其他事情,而且我更喜欢小的代码占用空间,这样我就可以定制和了解它的性能特征。
我喜欢 Node.js 的非阻塞特性,并且想知道是否有一个开源项目可以完成所有这些逻辑。
我还希望看到在客户端维护此模型的 JavaScript 实现。
Ideally, I'd like to find simple, lightweight code that allows all the web clients connected to my site to maintain real-time status of who else is currently online.
I know ejabberd does this, but it also does a lot of other things, and I'd prefer a small code footprint so I can customize and understand its performance characteristics.
I like the non-blocking aspect of node.js, and was wondering if there's an open source project that does all this logic.
I'd also like to see a JavaScript implementation of maintaining this model on the client side.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如需实时状态,请使用 socket.io。每次有人连接时,将他们添加到已连接的用户列表中。为了获得准确的统计数据,您需要跟踪用户会话。请参阅http://www.danielbaulig.de/socket-ioexpress/
For real time status, use socket.io. Every time someone connects add them to the connected users list. For accurate stats you will need to keep track of user sessions. See http://www.danielbaulig.de/socket-ioexpress/
对于任何将来阅读本文的人。我从
fent
写的答案开始,但我需要一些修改,因为自他的答案发布以来的 6 年里,情况发生了变化。我使用
Map
而不是Object
来存储会话信息。这意味着不再需要sessionID
。For anyone reading this in the future. I started with the answer written by
fent
, but I needed some modifications since things have changed in the intervening 6 years since his answer was published.I used a
Map
rather than anObject
for storing the session information. this means that thesessionID
is no longer required.