Socket.io Connected User Count

后端 未结 12 841
有刺的猬
有刺的猬 2021-01-30 20:24

I finally got socket.io to work properly, but I have encountered a strange problem.

I am not sure if this is the best way, but I am using:

io.sockets.cli         


        
12条回答
  •  日久生厌
    2021-01-30 21:14

    Tested using Socket.IO v2.3.0 using namespace, I found 4 locations having the clientCounts property (it's probably the same Server object each time):

    const socketio = require('socket.io');
    const io = socketio(http_server);
    
    const io_namespace = io.of('/foobar');
    
    io_namespace.on('connection', function(socket)
    {
        console.log(socket.conn.server.clientsCount);
        console.log(socket.server.engine.clientsCount);
        console.log(io.engine.clientsCount);
        console.log(io_namespace.server.engine.clientsCount);
    });
    

提交回复
热议问题