V
V
vetsmen2017-01-31 00:20:19
JavaScript
vetsmen, 2017-01-31 00:20:19

How do you count the number of socket.io connections?

How do you count the number of socket.io connections?
Tried to take connect/disconnect events and increase/decrease the counter accordingly
Tried to take the io.engine.clientsCount variable
But there is one problem everywhere - when the page is frequently updated, the counter increases, while the number of connections does not grow. As I understand it, the disconnect event does not have time to be called and the socket thinks that the user is still online.
I understand that you can do some minimal data exchange with users and at the same time determine how many users are alive, but are there any simpler ways?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Bublikov, 2017-01-31
@bublik462

Write to the event "io.sockets.on connection " - console.log(Object.keys(io.sockets.connected).length);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question