Sending message to specific client with socket.io and empty message queue

后端 未结 9 2021
误落风尘
误落风尘 2020-12-22 20:16

I´m going crazy with socket.io! Documentation is so bad it\'s simply not true.

I want to send a feedback to specific client over socket.io

My server side loo

9条回答
  •  遥遥无期
    2020-12-22 21:00

    to send a message to a specific client save every one that connects to the server in an Object.

    var socketio = require('socket.io');
    var clients = {};
    var io = socketio.listen(app);
    
    io.sockets.on('connection', function (socket) {
      clients[socket.id] = socket;
    });
    

    then you can later do something like this:

    var socket = clients[sId];
    socket.emit('show', {});
    

提交回复
热议问题