Book Image

SignalR Real-time Application Cookbook

By : Roberto Vespa
Book Image

SignalR Real-time Application Cookbook

By: Roberto Vespa

Overview of this book

Table of Contents (18 chapters)
SignalR Real-time Application Cookbook
About the Author
About the Reviewers

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:

  1. Add a Hub called EchoHub.

  2. Add an OWIN Startup class named Startup with a Configuration() method calling app.MapSignalR();.

  3. Add the following to the Hub code:

    using Microsoft.AspNet.SignalR;
    using Microsoft.AspNet.SignalR.Hubs;
    namespace Recipe08
        public class EchoHub : Hub
            public void Subscribe(string groupName)