After thoroughly researching the documentation, I am still unable to find a solution. My goal is to send data to a specific client or user instead of broadcasting it to everyone.
I have come across other inquiries regarding this issue, but most either remain unanswered or refer to outdated methods. Any assistance on this matter would be greatly appreciated.
The current code functions as intended but broadcasts the information to all users on the site rather than targeting an individual...
SERVER:
//Socket.io
const http = require('http').Server(app);
const io = require('socket.io')(http);
app.post('/login', (req, res) => {
const email = cryptonize.encrypt(req.body.email);
const password = cryptonize.encrypt(req.body.password);
io.emit('login success', email, password);
});
CLIENT:
const socket = io();
socket.on('login success', (user, token, auth) => {
console.log(`user:${user}, password:${password});
});
I have attempted using "socket.emit" as suggested in the socket.io cheat sheet, but it returns as undefined on the server. It is likely a simple oversight on my part, just need to pinpoint the mistake.