Socket.io recommends settings per-socket variables like so:
socket.set('foo', bar, function () {});
Variables can also be set and accessed on the socket:
socket.foo = bar
Is there a benefit to using the provided set() function?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Calling
socket.foosets your property on the socket object itself. This isn’t recommended because you could be overriding an internal property that socket uses and depends upon. When you callsocket.set()this is stored in an internal data structure that won’t clash with internal properties.https://github.com/LearnBoost/socket.io/blob/master/lib/socket.js#L246