How to set 2 users socket.id into 2 variables, user1id and user2id in socket.io/node.js

I've followed this chat tutorial http://cestfait.ch/content/chat-webapp-nodejs on creating a simple chat app, Ive been trying to limit this to just 2 users, and I wanted to create 2 variables called user1id, and user2id, I want them to be the socket.id of the client, like

// you set this value when the user1 connects
var user1id;

// you set this value when the user2 connects
var user2id;

// just for visualization, this is one of the questions I have on how to do this.
user1id = socket.id; user2id = socket.id;

the reason I want just 2 users and have them as user1 and user2 is so I can compare their messages, so I need an array of user1's and users 2's messages like

user1arr = []; user2arr = [];

and then just compare for example the "currentWord" variable of user1 and see if that matches anything in user2msgs[]. An example of user1's case below:

function receivedWord(userid, currentWord) {

// this means current player is 1
if( userid == user1id ) {

    // adds the word received to user 1 word array
    user1arr.push(currentWord);

    // compares received word with each word in user 2 array
    $.each(user2arr, function(u2word) {
        if(u2word == currentWord) {
            wordsMatch();
        }
    }
}

My code is basically that of the chat app I gave at the start of this post.

Thanks.

The problem that you will be having is that every time the user reloads the page, the socketID from socketIO will change. What you will need to do is attach something like a sessionID to the user so you know that even if he reconnects he is the same user. You will need to look at a webframe like expressJS or even connect which are highly flexible middlewares for nodeJS. I've accomplished such a thing with express, so let me get you started with a bit of code for this

//directories
var application_root = __dirname;

//general require
var express = require('express'),
        connect = require('connect'),
        http = require('http'),
        fs = require('fs');

//create express app
var app = express();

//create sessionStore
var sessionStore = new connect.session.MemoryStore();

//setup sessionKey
var secretKey = 'superdupersecret';

//configure express
app.configure(function() {

        //use body parser
        app.use(express.bodyParser());

        //override methods
        app.use(express.methodOverride());

        //cookies and sessions
        // BE AWARE: this lines have to be written before the router!
        app.use(express.cookieParser(secretKey));
        app.use(express.session({
                store: sessionStore,
                secret: secretKey,
                key: 'express.sid'
        }));

        //router
        app.use(app.router);

        //use static page in public folder
        app.use(express.static(path.join(application_root, 'public')));
});


//create the http server link to the new data http object of express 3
server = http.createServer(app);

//make server listen to 8080 and localhost requests
server.listen(8080, 'localhost', function() {
        console.log('Express Server running and listening');
});

//bind socket.io to express server by listening to the http server object
var io = require('socket.io').listen(server);

//set the authorization through cookies 
io.set('authorization', function(data, accept) {

        //check if header data is given from the user
        if (!data.headers.cookie) {

                //return false if no cookie was given
                return accept('Session cookie required!', false);
        }

        //parse cookie into object using the connect method
        //NOTE: this line is a hack, this is due to the fact
        //that the connect.utils.parseCookie has been removed
        //from the current connect module and moved to an own
        //instance called 'cookie'.
        data.cookie = connect.utils.parseSignedCookies(require('cookie').parse(decodeURIComponent(data.headers.cookie)), secretKey);

        //save session id based on exress.sid
        data.sessionID = data.cookie['express.sid'];

        //get associated session for this id
        sessionStore.get(data.sessionID, function(err, session) {
                if (err) {
                        //there was an error
                        return accept('Error in session store.', false)
                } else if (!session) {
                        //session has not been found
                        return accept('Session not found', false);
                }

                //successfully got the session, authed with known session
                data.session = session;

                //return the accepted connection
                return accept(null, true);
        });

});

//connection handler for new io socket connections
io.sockets.on('connection', function(socket) {

        //parse handshake from socket to io
        var hs = socket.handshake;

        //show session information
        console.log('New socket connection with sessionID ' + hs.sessionID + ' connected');

});

Just read through the code and the comments to understand what they are doing. Basically what you are doing is the create an express server, make the socketIO listen to it, create a sessionStore to make it globally available, lock it with a secretKey and set it to the authorization method of socketIO. What socket then does is making handshakes with the users and then links it to a express session. That means that the express sessionID stays the same throughout the session while socketIO ids switch all the time.