A metal chair
A metal chair

Reputation: 51

Socket.emit not working as intended

I am attempting to use node.js to create a login script. The user enters their information on a page and they are redirected to a validation page. The server than checks against a users database and confirms all the login info is matching.

The server then takes the client's socket and emits in this code:

    function emitverified(dbuser) {
    console.log(dbuser);
    io.to(dbuser).emit('l');
}

The client handles this in this code

socket.on('l', function () {
            console.log("Validation occurred successfully");
        });

At this time, the client is not receiving the l signal that is emitted.

Upvotes: 0

Views: 68

Answers (1)

John Pangilinan
John Pangilinan

Reputation: 1031

.to broadcast to a room. Join your client socket to dbuser first.

socket.join(dbuser);
server.to(dbuser).emit('l');

Upvotes: 1

Related Questions