Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR - get list of connected connection ids on the server

Tags:

signalr

In my hub, how do I get a list of all currently connected connectionIds?

Essentially, I'm doing some encryption (yes, I've talked to a bunch of people and nothing built-in works) and have an instance of Aes for each connection. So basically when I need to send a message to all clients I can't just do Clients.All but rather must manually enumerate all clients, fetch its Aes encoder (by id) and then send a message to it.

like image 744
George Mauer Avatar asked Apr 29 '16 22:04

George Mauer


People also ask

Is SignalR connection ID unique?

Each client connecting to a hub passes a unique connection id. You can retrieve this value in the Context. ConnectionId property of the hub context.

How long do SignalR connections stay open?

The default keepalive timeout period is currently 20 seconds. If your client code tries to call a Hub method while SignalR is in reconnecting mode, SignalR will try to send the command. Most of the time, such attempts will fail, but in some circumstances they might succeed.


1 Answers

You'll have to build a way to store the connected clients by yourself using OnConnect() and OnDisconnect().

Get number of listeners, clients connected to SignalR hub

like image 100
Florin Secal Avatar answered Oct 21 '22 10:10

Florin Secal