Noticed a strange feature of node.js.
For example:
Let's say, I've got some variable on node.js server: var user_id = '1';, in which the stored user id which is connected to the server.
user1 have var user = 1;
user2 have var user = 2;
...
user99 have var user = 99;
But if at some point I will demand from the server variable user - I will return the id of the last user who rewrote her.
Is that right? So it should be?
I thought, node.js for each user creates a flow/process ...
Thanks for your answer!
index.js
dNode({
connect: function(data, callback) {
IM.iUserId = data.user_id;
IM.start();
}
});
im.js
var IM = {
iUserId: false,
start: function() {
console.log(this.iUserId);
}
};
It seems like you have one global IM objects that all of your connections are sharing.
You can set/get a value for each socket by using socket.set and socket.get
Node.js is single thread one context, it does not create any isolated context for users like in PHP.
Everything inside is shared and cross-acessible.