Adding a connection to a group
Multiple clients can connect to a specific Hub at the same time, and the number of connections can easily increase. SignalR offers a feature called groups in order to define subsets of connections and use them when broadcasting to clients. We will see how a Hub can place connected clients into groups and then broadcast calls to all the connections belonging to a specific group.
Getting ready
Before writing the actual code, we need to create a new empty web application, which we'll call Recipe08
.
How to do it…
We're ready to start building our sample. We need to perform the following steps:
Add a Hub called
EchoHub
.Add an OWIN Startup class named
Startup
with aConfiguration()
method callingapp.MapSignalR();
.Add the following to the Hub code:
using Microsoft.AspNet.SignalR; using Microsoft.AspNet.SignalR.Hubs; namespace Recipe08 { [HubName("echo")] public class EchoHub : Hub { public void Subscribe(string groupName) { Groups...