Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8339707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:57:16+00:00 2026-06-09T04:57:16+00:00

I want to merge express.js and socket.io sessions together. Below is my code (socket.io

  • 0

I want to merge express.js and socket.io sessions together. Below is my code (socket.io part)

var io = require('socket.io').listen(app);
io.set('log level', 1);

io.sockets.on('connection', function (socket) {
    console.log('client connected');
client.send(client.id);//send client id to client itself
socket.on('connect', function(){
    console.log(socket.id + ' connected');
});
socket.on('disconnect', function(){
    console.log(socket.id + ' disconnected');
});
});

My express.js Session settings:

app.configure(function() {
  //app.use(express.logger());
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(express.static(__dirname + '/static'));
  app.use(express.cookieParser());
  app.use(express.session({store: MemStore({
    reapInterval: 60000 * 10
  }), secret:'foobar', key: 'express.sid'
}));

My main problem is in my terminal when user travels from one url to another, the session id changes also: But I don’t want it to be changed.

info  - socket.io started
client connected
client connected
4Z0bYHzfWCEFzbbe4WUK disconnected
e_uSvxhSLbLAC9-F4WUL disconnected
client connected
bKDy90gsrWWTRJDD4WUM disconnected
client connected
RJ5qqCL2wfmXbd7U4WUN disconnected
client connected
wjN5Sqx4rucRtWL_4WUO disconnected
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:57:17+00:00Added an answer on June 9, 2026 at 4:57 am

    You are outputting the socket ID, not the session ID from express.js.

    You must use the authorization event, its first parameter is an object which has an entry called sessionID. That value shouldn’t change between page reloads, as it is stored in a cookie (or redis database or whatever).

    Here is a good article explaining how it works: http://www.danielbaulig.de/socket-ioexpress/ , but it’s a little outdated. The basic principle stays the same, but a few details have changed. For example the way he creates the server doesn’t work anymore, and the connect developers have removed parseCookie(). Users are not happy with that decision, however the workaround is this easy-to-remember line of code:

    connect.utils.parseSignedCookies(cookie.parse(decodeURIComponent(data.headers.cookie)), secret);
    

    As I said, the article mentioned above should give you all the basics you need, if you want to see a working implementation, take a look at this: https://github.com/vortec/lolbr/blob/master/lib/lolbr.js

    Inside the authorization event handler, you can modify the data object and access it later it using socket.handshake, in your case: socket.handshake.sessionID.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to merge recursively arrays.. My code is: var allitemorder; var itemorder; $('.divclass').each(function
I have 2 arrays like below and want to merge them together and not
I want to merge two A3 Objects together which contain some of the same
I want to merge between my code that contains the Web service and the
I want merge the all td where classname='blahblah' Here is my Html Code: <table><tbody><tr>
I want merge 2 array collection, where no duplicates are allowed, var ac1:ArrayCollection =
I want to merge two bitmaps, here is my code // Camera arg conversion
I want to merge three xts objects together with cbind : > OIH.tmp <-
I want to merge all data in two arraylist in c#. Some data in
I want to merge two arrays and replace the text with strtr function. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.