Explain session support using Express and Socket.IO?

I am looking for some help in defining sessions on a server that relies on express and socket.io. Basically, the goal is to handle things like pairing socket.io session IDs with user IDs, mainting state on reconnection, and the ability to easily group all participants on the server.

Any help is greatly appreciated.

Thanks.

+7
source share
2 answers

I just downloaded a project that allows you to use your sessions from express to Socket.IO. Maybe this can help you. https://github.com/aviddiviner/Socket.IO-sessions

You can install it with npm install socket.io-sessions . Be sure to check out the README.

If you are new to Node, I would suggest spending some time reading through express documents on how they handle sessions. http://expressjs.com/guide.html#session-support

Finally, I also posted some code snippets here: socket.io and the session?

Hope this helps!

+5
source

If you are using socket.io v1 +, you can do this in a less hacked way using middleware. See https://github.com/peerigon/socket.io-session-middleware for middleware that shares sessions between socket.io, connect, express.

0
source

All Articles