Socket.io send data only a client who make request Socket.io send data only a client who make request express express

Socket.io send data only a client who make request


I assume that in the post method you have identified the user or session.

So you can create a room per user to later emit on it.

client.js

var room = "#usernameRoom";socket.on('connect', function() {   socket.emit('privateroom', room);});socket.on('privatemessage', function(data) {   console.log('Incoming private message:', data);});

server.js

io.sockets.on('connection', function(socket) {    var socket_room;    socket.on('privateroom', function(room) {        socket_room = room;        socket.join(room);    });    socket.on('disconnect', function() {        if (socket_room) {            socket.leave(socket_room);        }    });});app.post(.....){  myModel.save(function (err) {    if (err) return handleError(err);    ///send to all    io.sockets.emit("ev", { ...... });    //// send to one client    // now, it's easy to send a message to just the clients in a given private room    privateRoom = "#usernameRoom";    io.sockets.in(privateRoom ).emit('privatemessage', 'Never reveal your identity!'); });}

hope that helps