Monday, 1 May 2017

socket not emitting properly

so i have this code that should retrieve data from a database and send it to the client

socket.on('updatebalance', function (datas) {
            connection.query("SELECT balance FROM members WHERE username = '"+ datas.name +"'", function(err, data) {
                if (!err)
                {
                 var username = datas.name;
                 var balancee = data[0].balance;
                 socket.broadcast.to(username).emit('updatedbalance', { balance: balancee });

             }else{
                 console.log('error here'); 
             }
            });

    });

but it seems to not be working, this part in particular

socket.broadcast.to(username).emit('updatedbalance', { balance: balancee });

but whats strange is, when i put that code in with random data in a different event such as when a user connectes, it works. i have consolelogged the username and balancee variables and am sure they have data within them. any help?



via Brad m

No comments:

Post a Comment