Book Image

SignalR: Real-time Application Development - Second Edition

By : Einar Ingerbrigsten
Book Image

SignalR: Real-time Application Development - Second Edition

By: Einar Ingerbrigsten

Overview of this book

Table of Contents (19 chapters)
SignalR – Real-time Application Development Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
11
Hosting a Server Using Self-hosted OWIN
Index

Getting specific with groups


Many scenarios require you to not be broadcasting to everyone, but to be more specific in who receives the message. SignalR provides an abstraction called groups for these. Groups hold the connections that will receive messages. The API for sending messages is the same, but you just choose to go to a specific group instead of going to everyone.

For our chat applications, we want to use groups to create chat rooms; specific groups will receive chat messages that none of the other rooms/groups will receive. In order for us to get this working, we will need to change our application slightly as follows:

  1. First, we will need a class to manage the chat rooms that get created by any clients, so we keep track of them for any other clients that connect.

  2. Right-click on the project and select Add | New Item. In the dialog box, select Class and give it a name ChatRooms.cs:

  3. Basically, this class will just hold a list of strings that represent the different chat rooms by name...