socket.id 有多独特? [英] How unique is socket.id?

查看:24
本文介绍了socket.id 有多独特?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个应用程序,我希望在应用程序运行期间为每个连接提供一个唯一标识符,我想知道 socket.id 是否适用于此.例如.如果用户 1 与应用程序断开连接,即使用户 1 不再连接,稍后连接的用户 2 也不应该具有用户 1 之前拥有的相同 socket.id.在 socket.io 监听服务器的整个时间里,socket id 是唯一的吗?

I'm building an application where I'd like a unique identifier for every connection for the duration that the app is running and I'm wondering if socket.id works for this. E.g. if user 1 disconnects from the application, user 2 who connects later shouldn't have the same socket.id that user 1 had before even though user 1 is no longer connected. Are socket ids unique for the entire time socket.io is listening to the server?

推荐答案

假设您使用的是 socket.io@0.9.x(这是 NPM 中的当前版本),代码为每个连接/客户端生成一个新的 id 可以在这里找到.

Assuming that you're using socket.io@0.9.x (which is the present version in NPM), the code that generates a new id for each connection/client can be found here.

我认为您可以放心地假设每个套接字 ID 都是唯一的.

I think that you can safely assume that each socket id is going to be unique.

这篇关于socket.id 有多独特?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆