function(self, socket) {
  var app = self.app,
    sid = socket.id;
  var session = self.session.get(sid);
  if (session) {
    return session;
  }

  session = self.session.create(sid, app.getServerId(), socket);
  logger.debug('[%s] getSession session is created with session id: %s', app.getServerId(), sid);

  // bind events for session
  socket.on('disconnect', session.closed.bind(session));
  socket.on('error', session.closed.bind(session));
  session.on('closed', onSessionClose.bind(null, app));
  session.on('bind', function(uid) {
    logger.debug('session on [%s] bind with uid: %s', self.app.serverId, uid);
    // update connection statistics if necessary
    if (self.connection) {
      self.connection.addLoginedUser(uid, {
        loginTime: Date.now(),
        uid: uid,
        address: socket.remoteAddress.ip + ':' + socket.remoteAddress.port
      });
    }
    self.app.event.emit(events.BIND_SESSION, session);
  });

  session.on('unbind', function(uid) {
    if (self.connection) {
      self.connection.removeLoginedUser(uid);
    }
    self.app.event.emit(events.UNBIND_SESSION, session);
  });

  return session;
}
function(self, socket) {
  var app = self.app,
    sid = socket.id;
  var session = self.session.get(sid);
  if (session) {
    return session;
  }

  session = self.session.create(sid, app.getServerId(), socket);
  logger.debug('[%s] getSession session is created with session id: %s', app.getServerId(), sid);

  // bind events for session
  socket.on('disconnect', session.closed.bind(session));
  socket.on('error', session.closed.bind(session));
  session.on('closed', onSessionClose.bind(null, app));
  session.on('bind', function(uid) {
    logger.debug('session on [%s] bind with uid: %s', self.app.serverId, uid);
    // update connection statistics if necessary
    if (self.connection) {
      self.connection.addLoginedUser(uid, {
        loginTime: Date.now(),
        uid: uid,
        address: socket.remoteAddress.ip + ':' + socket.remoteAddress.port
      });
    }
    self.app.event.emit(events.BIND_SESSION, session);
  });

  session.on('unbind', function(uid) {
    if (self.connection) {
      self.connection.removeLoginedUser(uid);
    }
    self.app.event.emit(events.UNBIND_SESSION, session);
  });

  return session;
}
function ( self , socket ) { var app = self . app , sid = socket . id ; var session = self . session . get ( sid ) ; if ( session ) { return session ; } session = self . session . create ( sid , app . getServerId ( ) , socket ) ; logger . debug ( '[%s] getSession session is created with session id: %s' , app . getServerId ( ) , sid ) ; // bind events for session socket . on ( 'disconnect' , session . closed . bind ( session ) ) ; socket . on ( 'error' , session . closed . bind ( session ) ) ; session . on ( 'closed' , onSessionClose . bind ( null , app ) ) ; session . on ( 'bind' , function ( uid ) { logger . debug ( 'session on [%s] bind with uid: %s' , self . app . serverId , uid ) ; // update connection statistics if necessary if ( self . connection ) { self . connection . addLoginedUser ( uid , { loginTime : Date . now ( ) , uid : uid , address : socket . remoteAddress . ip + ':' + socket . remoteAddress . port } ) ; } self . app . event . emit ( events . BIND_SESSION , session ) ; } ) ; session . on ( 'unbind' , function ( uid ) { if ( self . connection ) { self . connection . removeLoginedUser ( uid ) ; } self . app . event . emit ( events . UNBIND_SESSION , session ) ; } ) ; return session ; }
get session for current connection
get session for current connection
get session from pool