Skip to content

Is there a way to get the number of sockets connected in a dynamic namespace ?? #435

Answered by Totodore
Axnjr asked this question in Q&A
Discussion options

You must be logged in to vote

If you want to get the number of sockets for this namespace variant:

let _ = io.dyn_ns("/{client_id}", |s: SocketRef, io: SocketIo| async move {
      let namespace_size = io.of(s.ns()).unwrap().sockets().unwrap().len(); // this should work
});

But if you want all the sockets of all the namespaces variants corresponding to this dynamic namespace, you can't. Currently dynamic namespace features are quite limited. It will be added to the roadmap though.

It is a bit hacky but can maintain an external counter or a set of the created namespaces and fetch + sum the number of sockets for each namespace.

Btw you can use SocketIo as a param extractor rather than cloning it:

let _ = io.dyn_ns("/{cl…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Axnjr
Comment options

Answer selected by Axnjr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants