I'm trying to build a private messaging app using socket.io. My assumption was that per session there would only ever be one socket.id. If i keep track of my socket.id and console.log it, it's constantly chnaging and I dont know why.
Here a snippet if how I am saving a new user.
//Listen on the connection for incoming sockets
io.on('connection',function (socket) {
console.log(socket.id)
//Add the users to the socket session
socket.on("add-user", function(username){
oCurrentUser = {
username: username,
id: socket.id
};
console.log("socket.id for this user is", oCurrentUser.id);
aClients.push(oCurrentUser);
console.log(aClients);
socket.emit('login',oCurrentUser);
});
});
Response after I create a users:
listening on *:3000
Vws9v-Wegjx4bvBKAAAA
e611mmTgdYmFvhuMAAAB
IPE95tFpgem0eyvyAAAC
m5YLVR0PE_Qqc-AcAAAD
GXbyRVYAnHgBz4VzAAAE
When I do console.log(socket.id)
is get like 5 ID's. I would of assumed it would return just one right?