I have this code here
io.on("connection", function(socket){
//other methods where emit works
socket.on("login", function(data) {
try {
pg.connect(conString, function(err, con) {
var query = con.query("SELECT * FROM accounts WHERE username" +
"='" + data.usn + "';");
query.on("row", function(row, result) result.addRow(row); });
query.on("end", function(result) {
if (sha512(data.pwd, result.rows[0].salt).hash ===
result.rows[0].password) {
socket.emit("loginResponse", { status: "Success" });
console.log("I GOT UP TO HERE WITHOUT EMITTING! WTF?");
console.log(sha512(data.pwd,result.rows[0].salt).hash);
console.log(result.rows[0].password);
}
});
});
} catch (ex) { console.log(ex); }
});
});
Obviously, on the client side, I have something like this:
socket.on("loginResponse", function(data) {
alert(data.status);
});
However, whenever I try to log in successfully, my server doesn't emit anything to the client, i.e. I will see the printed lines on my terminal but the client doesn't get a response from the server. I've been baffled by this. I have another function which touches the PostgreSQL driver and emits successfully, but this one doesn't. Does anyone know why this is the case?