Mr. Flibble
Mr. Flibble

Reputation: 27043

Send message to set of users within a group with SignalR

Is it possible to send a message to a selection of clients within a Group in SignalR?

...without having to maintain your own lists of subscribers and using context.Clients.Clients(includeConnectionIds[])

Upvotes: 2

Views: 177

Answers (2)

davidfowl
davidfowl

Reputation: 38885

In SignalR 2.0 you can send to a many groups or many connections in a single call via Clients.Groups or Clients.Clients.

Upvotes: 0

Kim See Jonge
Kim See Jonge

Reputation: 256

SignalR does not have state by default, or they actually do with groups... But it is not very dynamic. I had the same issue as you are having. I needed to send a message to a subset of a group.. Or actually I needed to send to clients where age was between x and y...

This is impossible with groups so you have to implement the functionality your self. Bloated and ugly...

I actually ended up using Xsocket.net instead where I can target client with lambda expressions without messing around with custom static lists/groups etc.

Do not know your requirements but sending to any subset if clients is done by:

this.SendTo(p => p.Age > x && p.Age < y, new {Message="hello world"},"message");

//Signature of the extension method is...
//SendTo<T>(this IXSocketController socket, Func<T, bool> expression, object obj, string eventname)
//So you can actually send to clients on any controller is specifying T

Best of luck with whatever you choose.

Upvotes: 1

Related Questions