Smitha Smitha - 5 months ago 21
Node.js Question

How unique is 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?

Answer

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.

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

Comments