By default, Socket.IO does not have a server-side logic for reconnecting. Which means each time a client wants to connect, a new socket object is created, thus it has a new id. It's up to you to implement reconnection.
In order to do so, you will need a way to store something for this user. If you have any kind of authentication (passport for example) - using socket.request you will have the initial HTTP request fired before the upgrade happened. So from there, you can have all kind of cookies and data already stored.
If you don't want to store anything in cookies, the easiest thing to do is send back to client specific information about himself, on connect. Then, when user tries to reconnect, send this information again. Something like:
var client2socket = {}; io.on('connect', function(socket) { var uid = Math.random(); // some really unique id :) client2socket[uid] = socket; socket.on('authenticate', function(userID) { delete client2socket[uid]; // remove the "new" socket client2socket[userID] = socket; // replace "old" socket }); });
Keep in mind this is just a sample and you need to implement something a little bit better :) Maybe send the information as a request param, or store it another way - whatever works for you.
socket.idwill uniquely identify a user instead of a connection. The server will generate a new id for each connection, and you can't override that.socket.io-clientis to reconnect automatically (documented here, thereconnectionoption).