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

Broadcasting to all clients in a group except the caller

Similar to what we just did in order to exclude specific connections from the set of all the connected clients, we can provide exceptions in the context of a specific group. We can broadcast to all the connections in a given group, excluding a list of specific ConnectionId values that we want to omit.

Getting ready

Before writing the code of this recipe, we create a new empty web application, which we'll call Recipe12.

How to do it…

Let's prepare our project by performing the following steps:

  1. We add a Hub called EchoHub.

  2. Let's then add the usual OWIN Startup class named Startup, with a Configuration() method calling app.MapSignalR().

  3. Let's edit Hub's content using the following code:

    using Microsoft.AspNet.SignalR;
    using Microsoft.AspNet.SignalR.Hubs;
    namespace Recipe12
        public class EchoHub : Hub
            public void Subscribe(string groupName)
                Groups.Add(Context.ConnectionId, groupName...