Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
C# 7 and .NET Core 2.0 Blueprints

You're reading from   C# 7 and .NET Core 2.0 Blueprints Build effective applications that meet modern software requirements

Arrow left icon
Product type Paperback
Published in Mar 2018
Publisher
ISBN-13 9781788396196
Length 428 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Dirk Strauss Dirk Strauss
Author Profile Icon Dirk Strauss
Dirk Strauss
Jas Rademeyer Jas Rademeyer
Author Profile Icon Jas Rademeyer
Jas Rademeyer
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. eBook Manager and Catalogue App FREE CHAPTER 2. Cricket Score Calculator and Tracker 3. Cross Platform .NET Core System Info Manager 4. Task Bug Logging ASP .NET Core MVC App 5. ASP.NET SignalR Chat Application 6. Web Research Tool with Entity Framework Core 7. A Serverless Email Validation Azure Function 8. Twitter Clone Using OAuth 9. Using Docker and ASP.NET Core 10. Other Books You May Enjoy

Building the server


We'll need to build a server for our chat program, which will contain the methods we want to call from our connected clients. We'll use the SignalR Hubs API, which provides the methods needed for connected clients to communicate with our chat server.

SignalR Hub subclass

We now need to create the SignalR Hub. To do this, perform the following steps:

  1. Add a class to your project to handle the server-side of the chat. We'll call it Chat:

This will need to be a subclass of the SignalR Hub class. Make sure to add the using directive for Micosoft.AspNetCore.SignalR. Visual Studio's Quick Actions works well for this:

  1. Now add a Task method to the class to handle the sending of the messages:
        public Task Send(string sender, string message) 
        { 
            return Clients.All.InvokeAsync("UpdateChat", sender, 
            message); 
        } 

This method will be called through any of the connected clients and will invoke all connected clients' Send function, passing through...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image