I make two web application which listen on port 1234 and 5678. (I am using Express js)
And I store some session value while login. Suppose I store some string (like :"person1") in session while login on first application(on port 1234), Then I store some string (like : "person2") in session while login on second application(on port 5678). When person2 login in second application at that time it destroy session of first application (!!?) then if I refresh page, it loggedout due to session destroy.
Server side connection (First application which 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 which 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 Help Me ...
Thanks in advance.
Both your apps are using Express's (and therefore Connect's) MemoryStore to store the session data. Each app creates its own MemoryStore object, so neither knows about the other's session data.
Either use some other method of session storage (e.g. redis), or define your own storage method (see Connect's documentation) to use an object shared between both apps (assuming that they're both part of the same node.js process).