Socket.io Connected User Count

后端 未结 12 838
有刺的猬
有刺的猬 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:07

    I'm using socket.io 0.9.10 and the following code to determine the number of sockets:

    var socketIO =  require('socket.io').listen( .....
    var numberOfSockets = Object.keys(socketIO.connected).length;
    

    Not sure how accurate this number reacts to the various edge-cases, but 'til now it seems accurate: every browser connecting increases the number, every browser closed decreases it.

提交回复
热议问题