node.js - Two websocket override session value -


i make 2 web application listen on port 1234 , 5678. (i using express js)

and store session value while login. suppose store string (like :"person1") in session while login on first application(on port 1234), store string (like : "person2") in session while login on second application(on port 5678). when person2 login in second application @ time destroy session of first application (!!?) if refresh page, loggedout due session destroy.

server side connection (first application listen on port 1234)

var express = require('express'),     sio = require('socket.io');  app = express.createserver();  app.configure('development', function(){ app.use(express.bodyparser()); app.use(express.cookieparser()); app.use(express.session({secret: "hello1"}));     app.use(express.static(__dirname + '/'));     app.set('views', __dirname + '/views');     app.use(express.errorhandler({dumpexceptions: true, showstack: true}));     app.use(app.router); });  app.listen(1234); app.get('/login', function (req, res) {     req.session.uname = req.body.uname;     .     .     .     .     . }); var io = sio.listen(app); 

server side connection (second application listen on port 5678)

app.get('/login', function (req, res) {     req.session.uname = req.body.uname;     .     .     .     .     . }); app.listen(5678); var io = sio.listen(app); 

=========================================================================

client side connection (first application [1234])

<script type="text/javascript" src="/socket.io/socket.io.js" ></script> <script>       var socket = io.connect("http://"+mylocalip+":1234"); </script> 

client side connection (second application [5678])

<script type="text/javascript" src="/socket.io/socket.io.js" ></script> <script>       var socket = io.connect("http://"+mylocalip+":5678"); </script> 

please me ...

thanks in advance.

both apps using express's (and therefore connect's) memorystore store session data. each app creates own memorystore object, neither knows other's session data.

either use other method of session storage (e.g. redis), or define own storage method (see connect's documentation) use object shared between both apps (assuming they're both part of same node.js process).


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -