can i give my own id to a connected socket in nodejs

am trying to implement a multiuser communication app. I want to identify a user's socket with his id, so can i set socket's id to user' id like

socket.id=user.userId;

Here

client side

var socket = io.connect();
     socket.on('connect', function () {
          console.log("client connection done.....");
          socket.emit('setUserId','random value');
});

On server side

io.sockets.on('connection', function (socket) {
       socket.on('setUserId',function(uId){
             socket.userId = uId;
        });
});

This may help...

This may help you

io.sockets.on('connection', function (socket) {    
    console.log("==== socket  ===");
    console.log(socket.id);
    socket.broadcast.emit('updatedid', socket.id);
});

you can save socket id in client side. When you want 1-1 message (private chat) use updated socket id. Some thing like this :

io.sockets.socket(id).emit('private message', msg, mysocket.id) 

You can do this, but use property that doesn't clash with Node.js or any other frameworks keys

socket.myappsuperuserid = user.userId;