Socket.io Connected User Count

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

    I have found the way to figure it out in version 1.3.7. There are three methods as follows:

    1. io.engine.clientsCount
    2. io.sockets.sockets.length
    3. Object.keys(io.sockets.connected).length

    Hope these can help someone with the same issue.:)

提交回复
热议问题