Thursday 20 June 2019

Socket.io and socket properties

Hi, I a beginner in node and socket.io. Working on the chat to get some experience, I want to store my users names in an array for later use.On the client side I get a string from user input and store it as a name and then I add a property to my socket : Socket. nickname = nameAnd on the server side I have:``` io.on('connect', function (socket) { console.log(socket.nickname != undefined);if (socket.nickname != undefined) { console.log("here") connectedSockets.push([socket.id, socket.nickname]); socket.arrayIndex = connectedSockets.length - 1; console.log(socket.arrayIndex + " " + socket.nickname) console.log(connectedSockets); } });```The problem is that it will print the line only once:console.log(socket.nickname != undefined);And not enter the if once the nickname has been set. I’m obviously missing something there, could you give give me some advices to solve this? Thanks

Submitted June 20, 2019 at 10:57AM by StrenghGeek

No comments:

Post a Comment