and session?

By : sfs

I'm using express framework. I want to reach session data from I tried express dynamicHelpers with client.listener.server.dynamicViewHelpers data, but i can't get session data. Is there a simple way to do this? Please see the code


var io = require('');
var io = io.listen(app);

io.on('connection', function(client){
    // I want to use session data here
    client.on('message', function(message){
        // or here
    client.on('disconnect', function(){
        // or here
By : sfs


You can have a look at this:

or alternatively you can use:

io.on('connection', function(client) { 
  var session = client.listener.server.viewHelpers; 
  // use session here 

Hope this helps.

I am not sure that I am doing it right.

With the handshake data, you can access to the cookies. And in the cookies, you can grab connect.sid which is the session id for each client. And then use the connect.sid to get the session data from database (I am assuming you are using RedisStore)

Check out Socket.IO-connect

Connect WebSocket Middleware Wrapper Around Socket.IO-node

This will allow you to push the Socket.IO request(s) down the Express/Connect middleware stack before handling it with Socket.IO event handlers, giving you access to the session, cookies, and more. Although, I'm not sure that it works with all of Socket.IO's transports.

By : BMiner

This video can help you solving your question :)
By: admin