SlideShare a Scribd company logo
1 of 50
Real-Time Communication with SignalR
2
 Understand Real-Time Communication application
 Understand the concepts of creating ASP.NET Core with SignalR
 Transports
 Hubs
 Create a simple chat system using ASP.NET Core with SignalR
 Work with Entity Framework combined with SignalR
7/21/2022
Objectives
7/21/2022 3
Real Time Web Applications - 1

Traditional Web Approach
Real Time Web Applications
7/21/2022 4
Real Time Web Applications - 2
 “Real Time” means an immediate response being sent by the Server to the
Client.
 Real Time is “Pushing” instead of “Pulling”
 Push Technology is completely different from Pull Technology. Its about getting
told what’s new, instead of asking for what’s new!
7/21/2022 5
Introducing SignalR
 SignalR is a library from Microsoft that offers real-time web development for
ASP.NET applications.
 SignalR is primarily used by applications that require push notifications from
server to client (applications such as chat, stock market, gaming, and
dashboards).
 SignalR solves the problem by providing a persistent connection between the
client and the server. SignalR uses the Hubs API to push notifications from
server to client, and it supports multiple channels such as WebSocket, server-
sent events, and long polling.
 SignalR supports multiple clients ranging from C#/C++ to JavaScript.
7/21/2022 6
History of SignalR
 SignalR was created in 2011 by David Fowler and Damian Edwards.
 SignalR was brought into the ASP.NET project and released as part of
ASP.NET in 2013.
 SignalR was set up to solve real-time messaging for the Web problem and
provide easy support for real-time capabilities on the ASP.NET stack by
creating server- and client-side libraries that abstract away the complications
of these technologies.
7/21/2022 7
Features of SignalR for ASP.NET Core
 SignalR provides an API for creating server-to-client remote procedure calls
(RPC). The RPCs call JavaScript functions on clients from server-side .NET
Core code.
 Handles connection management automatically.
 Sends messages to all connected clients simultaneously. For example, a chat
room.
 Sends messages to specific clients or groups of clients.
 Scales to handle increasing traffic.
7/21/2022 8
SignalR high-level architecture
 The ASP.NET Core SignalR high-level architecture
7/21/2022 9
SignalR Connections
 “SignalR supports "server push" functionality, in which server code can call
out to client code in the browser using Remote Procedure Calls (RPC), rather
than the request-response model common on the web today.
7/21/2022 10
Transports
 SignalR supports the following techniques for handling real-time
communication (in order of graceful fallback):
 WebSockets
 Server-Sent Events
 Long Polling
 SignalR automatically chooses the best transport method that is within the
capabilities of the server and client.
7/21/2022 11
Hubs - 1
 SignalR uses hubs to communicate between clients and servers.
 A hub is a high-level pipeline that allows a client and server to call methods on
each other.
 SignalR handles the dispatching across machine boundaries automatically,
allowing clients to call methods on the server and vice versa. You can pass
strongly-typed parameters to methods, which enables model binding.
 SignalR provides two built-in hub protocols:
 a text protocol based on JSON
 a binary protocol based on MessagePack
7/21/2022 12
Hubs - 2
 MessagePack generally creates smaller messages compared to JSON.
 Older browsers must support XHR level 2 to provide MessagePack protocol
support.
 Hubs call client-side code by sending messages that contain the name and
parameters of the client-side method.
 Objects sent as method parameters are deserialized using the configured
protocol.
 The client tries to match the name to a method in the client-side code.
 When the client finds a match, it calls the method and passes to it the
deserialized parameter data.
7/21/2022 13
Hubs - 3
 MessagePack is an efficient binary serialization format.
 It lets you exchange data among multiple languages like JSON. But it's faster
and smaller. Small integers are encoded into a single byte, and typical short
strings require only one extra byte in addition to the strings themselves.

7/21/2022 14
Use hubs in SignalR for ASP.NET Core
 The SignalR Hubs API enables you to call methods on connected clients from
the server.
 In the server code, you define methods that are called by client.
 In the client code, you define methods that are called from the server.
 SignalR takes care of everything behind the scenes that makes real-time
client-to-server and server-to-client communications possible.
7/21/2022 15
Create and use hubs
 Create a hub by declaring a class that inherits from Hub, and add public
methods to it.
 Clients can call methods that are defined as public.
7/21/2022 16
Configure SignalR hubs
 The SignalR middleware requires some services, which are configured by
calling services.AddSignalR();
 When adding SignalR functionality to an ASP.NET Core app, setup SignalR
routes by calling endpoint.MapHub in the Startup.Configure method's
app.UseEndpoints callback.
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<ChatHub>("/chathub");
});
7/21/2022 17
The Context object - 1
 The Hub class has a Context property that contains the properties with
information about the connection
Property Description
ConnectionId
Gets the unique ID for the connection, assigned by SignalR. There is one connection ID for each
connection.
UserIdentifier
Gets the user identifier. By default, SignalR uses the ClaimTypes.NameIdentifier from the
ClaimsPrincipal associated with the connection as the user identifier.
User Gets the ClaimsPrincipal associated with the current user.
Items
Gets a key/value collection that can be used to share data within the scope of this connection. Data
can be stored in this collection and it will persist for the connection across different hub method
invocations.
Features
Gets the collection of features available on the connection. For now, this collection isn't needed in
most scenarios, so it isn't documented in detail yet.
ConnectionAborted Gets a CancellationToken that notifies when the connection is aborted.
7/21/2022 18
The Context object - 2
 Hub.Context also contains the methods
Method Description
GetHttpContext
Returns the HttpContext for the connection, or null if the connection is not
associated with an HTTP request. For HTTP connections, you can use this
method to get information such as HTTP headers and query strings.
Abort Aborts the connection.
7/21/2022 19
The Clients object - 1
 The Hub class has a Clients property that contains the following properties for
communication between server and client
Property Description
All Calls a method on all connected clients
Caller Calls a method on the client that invoked the hub method
Others
Calls a method on all connected clients except the client that invoked the
method
7/21/2022 20
The Clients object - 2
 Hub.Clients also contains the following methods
Method Description
AllExcept Calls a method on all connected clients except for the specified connections
Client Calls a method on a specific connected client
Clients Calls a method on specific connected clients
Group Calls a method on all connections in the specified group
GroupExcept Calls a method on all connections in the specified group, except the specified connections
Groups Calls a method on multiple groups of connections
OthersInGroup Calls a method on a group of connections, excluding the client that invoked the hub method
User Calls a method on all connections associated with a specific user
Users Calls a method on all connections associated with the specified users
7/21/2022 21
Send messages to clients
 To make calls to specific clients, use the properties of the Clients object.
SendMessage() sends a message
to all connected clients, using
Clients.All.
SendMessageToCaller() sends a
message back to the caller, using
Clients.Caller.
SendMessageToGroup() sends a
message to all clients in the
SignalR Users group.
7/21/2022 22
Strongly typed hubs
 A drawback of using SendAsync is that it relies on a magic string to specify
the client method to be called.
 This leaves code open to runtime errors if the method name is misspelled or
missing from the client.
 An alternative to using SendAsync is to strongly type the Hub with Hub<T>.
7/21/2022 23
Change the name of a hub method
 By default, a server hub method name is the name of the .NET method.
 Can use the [HubMethodName] attribute to change this default and manually
specify a name for the method.
 The client should use this name, instead of the .NET method name, when
invoking the method.
7/21/2022 24
Handle events for a connection - 1
 The SignalR Hubs API provides the OnConnectedAsync and
OnDisconnectedAsync virtual methods to manage and track connections.
 Override the OnConnectedAsync virtual method to perform actions when a
client connects to the Hub, such as adding it to a group.
 Override the OnDisconnectedAsync virtual method to perform actions when a client
disconnects. If the client disconnects intentionally (by calling connection.stop(), for
example), the exception parameter will be null. However, if the client is disconnected
due to an error (such as a network failure), the exception parameter will contain an
exception describing the failure.
7/21/2022 25
Handle events for a connection - 2

7/21/2022 26
Handle errors
 Exceptions thrown in your hub methods are sent to the client that invoked the
method.
 On the JavaScript client, the invoke method returns a JavaScript Promise.
 When the client receives an error with a handler attached to the promise using
catch, it's invoked and passed as a JavaScript Error object.
7/21/2022 27
Hub filters - 1
 Are available in ASP.NET Core 5.0 or later.
 Allow logic to run before and after hub methods are invoked by clients.
 Work with Hub filter
 Create hub filters
 Configure hub filters
 Use hub filters
7/21/2022 28
Hub filters - 2
 Create hub filters
 Create a filter by declaring a class that inherits from IHubFilter, and add the
InvokeMethodAsync method.
 There is also OnConnectedAsync and OnDisconnectedAsync that can
optionally be implemented to wrap the OnConnectedAsync and
OnDisconnectedAsync hub methods respectively.
7/21/2022 29
Hub filters - 3
7/21/2022 30
Hub filters - 4
 Configure hub filters
 Hub filters can be applied globally or per hub type.
 The order in which filters are added is the order in which the filters run.
Global hub filters run before local hub filters.
7/21/2022 31
Hub filters - 5
 When writing the filter logic, try to make it generic by using attributes on hub
methods instead of checking for hub method names.
 Consider a filter that will check a hub method argument for banned phrases
and replace any phrases it finds with ***
Simple Chat with SignalR
7/21/2022 33
Create simple chat with ASP.NET Core SignalR
 Step 1. Create a web project.
 Step 2. Add the SignalR client library.
 Step 3. Create a SignalR hub.
 Step 4. Configure the project to use SignalR.
 Step 5. Add code that sends messages from any client to all connected clients.
7/21/2022 34
Step 1. Create a web project.

7/21/2022 35
Step 2. Add the SignalR client library.

7/21/2022 36
Step 3. Create a SignalR hub.
 A hub is a class that serves as a high-level pipeline that handles client-server
communication.
 Create a ChatHub.cs
 The ChatHub class inherits from the SignalR Hub class. The Hub class
manages connections, groups, and messaging.
 The SendMessage method can be called by a connected client to send a
message to all clients.
7/21/2022 37
Step 4. Configure the project to use SignalR.
 The SignalR server must be
configured to pass SignalR
requests to SignalR.
7/21/2022 38
Step 5. Add code that sends messages
 Add code that sends messages from any client to all connected clients
7/21/2022 39
Step 6. Run application

Create an application with Entity
Framework and SignalR
7/21/2022 41
Entity Framework combined with SignalR
 Step 1. Create Project
 Step 2. Work with Entity Framework
 Step 3. Create SignalR Hub and configure SignalR
 Step 4. Build CRUD functions combined with SignalR
 Step 5. Build and run Project. Test all CRUD actions
7/21/2022 42
Step 1. Create Project
7/21/2022 43
Step 2. Work with Entity Framework
 Install the following packages from NuGet:
 Add “Products.cs” entity and “ApplicationDBContext.cs” classes
 Add-Migration and Update-Database
 Add ProductsController with Scraffolding
7/21/2022 44
Step 2. Work with Entity Framework - 2
7/21/2022 45
Step 3. Create SignalR Hub and configure
 Create SignalR Hubs in the SignalrServer.cs
 Add SignalR to Startup.cs
7/21/2022 46
Step 4. CRUD functions with SignalR - 1
 Add Client-Side Library to Project
 Create a callback function in the script (site.js)
 Add the notification to CRUD actions
 Add SignalR JavaScript client to View
7/21/2022 47
Step 4. CRUD functions with SignalR - 2
 Create a callback
function in the script
(site.js)
7/21/2022 48
Step 4. CRUD functions with SignalR - 3
 Update the list of products in the Create, Edit and Delete functions
7/21/2022 49
Step 5. Build and run Project. Test all actions

Client 1 Client 2
Summary
 Concepts were introduced:
 Real-Time Communication application
 Creating ASP.NET Core with SignalR
 Transports
 Hubs
 Create a simple chat system using ASP.NET Core with SignalR
 Work with Entity Framework combined with SignalR
50

More Related Content

Similar to Real-Time Communication

IRJET- Development of Android Application for Device to Device Communication ...
IRJET- Development of Android Application for Device to Device Communication ...IRJET- Development of Android Application for Device to Device Communication ...
IRJET- Development of Android Application for Device to Device Communication ...IRJET Journal
 
Chat application with Azure SignalR Service
Chat application with Azure SignalR ServiceChat application with Azure SignalR Service
Chat application with Azure SignalR ServiceKrunal Trivedi
 
Android chapter16-web-services
Android chapter16-web-servicesAndroid chapter16-web-services
Android chapter16-web-servicesAravindharamanan S
 
Fancy Features in Asp.Net Core SignalR
Fancy Features in Asp.Net Core SignalRFancy Features in Asp.Net Core SignalR
Fancy Features in Asp.Net Core SignalRVladimir Georgiev
 
Real-Time Applications with SignalR and Vue by Girish Sonewane.docx.pdf
Real-Time Applications with SignalR and Vue by Girish Sonewane.docx.pdfReal-Time Applications with SignalR and Vue by Girish Sonewane.docx.pdf
Real-Time Applications with SignalR and Vue by Girish Sonewane.docx.pdfPolyxer Systems
 
IRJET- An Efficient Dissemination and Dynamic Risk Management in Wireless Sen...
IRJET- An Efficient Dissemination and Dynamic Risk Management in Wireless Sen...IRJET- An Efficient Dissemination and Dynamic Risk Management in Wireless Sen...
IRJET- An Efficient Dissemination and Dynamic Risk Management in Wireless Sen...IRJET Journal
 
IRJET- An Efficient Dissemination and Dynamic Risk Management in Wireless...
IRJET-  	  An Efficient Dissemination and Dynamic Risk Management in Wireless...IRJET-  	  An Efficient Dissemination and Dynamic Risk Management in Wireless...
IRJET- An Efficient Dissemination and Dynamic Risk Management in Wireless...IRJET Journal
 
Schema-based multi-tenant architecture using Quarkus &amp; Hibernate-ORM.pdf
Schema-based multi-tenant architecture using Quarkus &amp; Hibernate-ORM.pdfSchema-based multi-tenant architecture using Quarkus &amp; Hibernate-ORM.pdf
Schema-based multi-tenant architecture using Quarkus &amp; Hibernate-ORM.pdfseo18
 
Architecting Microservices in .Net
Architecting Microservices in .NetArchitecting Microservices in .Net
Architecting Microservices in .NetRichard Banks
 
Middleware in Distributed System-RPC,RMI
Middleware in Distributed System-RPC,RMIMiddleware in Distributed System-RPC,RMI
Middleware in Distributed System-RPC,RMIPrajakta Rane
 
PRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGE
PRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGEPRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGE
PRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGEEditor IJCTER
 
Inter Process Communication (IPC) in Android
Inter Process Communication (IPC) in AndroidInter Process Communication (IPC) in Android
Inter Process Communication (IPC) in AndroidMalwinder Singh
 
Applying Code Customizations to Magento 2
Applying Code Customizations to Magento 2 Applying Code Customizations to Magento 2
Applying Code Customizations to Magento 2 Igor Miniailo
 
Manual redes - network programming with j2 me wireless devices
Manual   redes - network programming with j2 me wireless devicesManual   redes - network programming with j2 me wireless devices
Manual redes - network programming with j2 me wireless devicesVictor Garcia Vara
 
How to Monitor Application Performance in a Container-Based World
How to Monitor Application Performance in a Container-Based WorldHow to Monitor Application Performance in a Container-Based World
How to Monitor Application Performance in a Container-Based WorldKen Owens
 

Similar to Real-Time Communication (20)

Remoting and serialization
Remoting and serializationRemoting and serialization
Remoting and serialization
 
IRJET- Development of Android Application for Device to Device Communication ...
IRJET- Development of Android Application for Device to Device Communication ...IRJET- Development of Android Application for Device to Device Communication ...
IRJET- Development of Android Application for Device to Device Communication ...
 
Socket
SocketSocket
Socket
 
Chat application with Azure SignalR Service
Chat application with Azure SignalR ServiceChat application with Azure SignalR Service
Chat application with Azure SignalR Service
 
Android chapter16-web-services
Android chapter16-web-servicesAndroid chapter16-web-services
Android chapter16-web-services
 
Introduction to SignalR
Introduction to SignalRIntroduction to SignalR
Introduction to SignalR
 
Fancy Features in Asp.Net Core SignalR
Fancy Features in Asp.Net Core SignalRFancy Features in Asp.Net Core SignalR
Fancy Features in Asp.Net Core SignalR
 
Real-Time Applications with SignalR and Vue by Girish Sonewane.docx.pdf
Real-Time Applications with SignalR and Vue by Girish Sonewane.docx.pdfReal-Time Applications with SignalR and Vue by Girish Sonewane.docx.pdf
Real-Time Applications with SignalR and Vue by Girish Sonewane.docx.pdf
 
Signal r
Signal rSignal r
Signal r
 
IRJET- An Efficient Dissemination and Dynamic Risk Management in Wireless Sen...
IRJET- An Efficient Dissemination and Dynamic Risk Management in Wireless Sen...IRJET- An Efficient Dissemination and Dynamic Risk Management in Wireless Sen...
IRJET- An Efficient Dissemination and Dynamic Risk Management in Wireless Sen...
 
IRJET- An Efficient Dissemination and Dynamic Risk Management in Wireless...
IRJET-  	  An Efficient Dissemination and Dynamic Risk Management in Wireless...IRJET-  	  An Efficient Dissemination and Dynamic Risk Management in Wireless...
IRJET- An Efficient Dissemination and Dynamic Risk Management in Wireless...
 
Schema-based multi-tenant architecture using Quarkus &amp; Hibernate-ORM.pdf
Schema-based multi-tenant architecture using Quarkus &amp; Hibernate-ORM.pdfSchema-based multi-tenant architecture using Quarkus &amp; Hibernate-ORM.pdf
Schema-based multi-tenant architecture using Quarkus &amp; Hibernate-ORM.pdf
 
Architecting Microservices in .Net
Architecting Microservices in .NetArchitecting Microservices in .Net
Architecting Microservices in .Net
 
Middleware in Distributed System-RPC,RMI
Middleware in Distributed System-RPC,RMIMiddleware in Distributed System-RPC,RMI
Middleware in Distributed System-RPC,RMI
 
PRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGE
PRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGEPRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGE
PRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGE
 
SignalR Overview
SignalR OverviewSignalR Overview
SignalR Overview
 
Inter Process Communication (IPC) in Android
Inter Process Communication (IPC) in AndroidInter Process Communication (IPC) in Android
Inter Process Communication (IPC) in Android
 
Applying Code Customizations to Magento 2
Applying Code Customizations to Magento 2 Applying Code Customizations to Magento 2
Applying Code Customizations to Magento 2
 
Manual redes - network programming with j2 me wireless devices
Manual   redes - network programming with j2 me wireless devicesManual   redes - network programming with j2 me wireless devices
Manual redes - network programming with j2 me wireless devices
 
How to Monitor Application Performance in a Container-Based World
How to Monitor Application Performance in a Container-Based WorldHow to Monitor Application Performance in a Container-Based World
How to Monitor Application Performance in a Container-Based World
 

More from ssusere19c741

0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdfssusere19c741
 
0-Slot18-19-20-ContiguousStorage.pdf
0-Slot18-19-20-ContiguousStorage.pdf0-Slot18-19-20-ContiguousStorage.pdf
0-Slot18-19-20-ContiguousStorage.pdfssusere19c741
 
0-Slot14-15-16-Libraries.pdf
0-Slot14-15-16-Libraries.pdf0-Slot14-15-16-Libraries.pdf
0-Slot14-15-16-Libraries.pdfssusere19c741
 
0-Slot13-Programming-With-Menu.pdf
0-Slot13-Programming-With-Menu.pdf0-Slot13-Programming-With-Menu.pdf
0-Slot13-Programming-With-Menu.pdfssusere19c741
 
0-Slot11-12-Pointers.pdf
0-Slot11-12-Pointers.pdf0-Slot11-12-Pointers.pdf
0-Slot11-12-Pointers.pdfssusere19c741
 
0-Slot08-09-10-Module-Functions.pdf
0-Slot08-09-10-Module-Functions.pdf0-Slot08-09-10-Module-Functions.pdf
0-Slot08-09-10-Module-Functions.pdfssusere19c741
 
0-Slot05-06-07-Basic-Logics.pdf
0-Slot05-06-07-Basic-Logics.pdf0-Slot05-06-07-Basic-Logics.pdf
0-Slot05-06-07-Basic-Logics.pdfssusere19c741
 
0-Slot02-Introduction-to-PFC.pdf
0-Slot02-Introduction-to-PFC.pdf0-Slot02-Introduction-to-PFC.pdf
0-Slot02-Introduction-to-PFC.pdfssusere19c741
 
Intro-InstallingTool-FirstProgram
Intro-InstallingTool-FirstProgramIntro-InstallingTool-FirstProgram
Intro-InstallingTool-FirstProgramssusere19c741
 
Background Tasks with Worker Service
Background Tasks with Worker ServiceBackground Tasks with Worker Service
Background Tasks with Worker Servicessusere19c741
 
Building Websites Using ASP.NET Core Razor Pages
Building Websites Using ASP.NET Core Razor PagesBuilding Websites Using ASP.NET Core Razor Pages
Building Websites Using ASP.NET Core Razor Pagesssusere19c741
 
Dependency Injection in .NET
Dependency Injection in .NETDependency Injection in .NET
Dependency Injection in .NETssusere19c741
 
Asynchronous and Parallel Programming in .NET
Asynchronous and Parallel Programming in .NETAsynchronous and Parallel Programming in .NET
Asynchronous and Parallel Programming in .NETssusere19c741
 
Networking Programming
Networking ProgrammingNetworking Programming
Networking Programmingssusere19c741
 
Working with XML and JSON Serializing
Working with XML and JSON SerializingWorking with XML and JSON Serializing
Working with XML and JSON Serializingssusere19c741
 
Building Windows Presentation Foundation (WPF) Application
Building Windows Presentation Foundation (WPF) ApplicationBuilding Windows Presentation Foundation (WPF) Application
Building Windows Presentation Foundation (WPF) Applicationssusere19c741
 
Building Windows Presentation Foundation (WPF) Application
Building Windows Presentation Foundation (WPF) ApplicationBuilding Windows Presentation Foundation (WPF) Application
Building Windows Presentation Foundation (WPF) Applicationssusere19c741
 

More from ssusere19c741 (19)

0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf
 
0-Slot18-19-20-ContiguousStorage.pdf
0-Slot18-19-20-ContiguousStorage.pdf0-Slot18-19-20-ContiguousStorage.pdf
0-Slot18-19-20-ContiguousStorage.pdf
 
0-Slot14-15-16-Libraries.pdf
0-Slot14-15-16-Libraries.pdf0-Slot14-15-16-Libraries.pdf
0-Slot14-15-16-Libraries.pdf
 
0-Slot13-Programming-With-Menu.pdf
0-Slot13-Programming-With-Menu.pdf0-Slot13-Programming-With-Menu.pdf
0-Slot13-Programming-With-Menu.pdf
 
0-Slot11-12-Pointers.pdf
0-Slot11-12-Pointers.pdf0-Slot11-12-Pointers.pdf
0-Slot11-12-Pointers.pdf
 
0-Slot08-09-10-Module-Functions.pdf
0-Slot08-09-10-Module-Functions.pdf0-Slot08-09-10-Module-Functions.pdf
0-Slot08-09-10-Module-Functions.pdf
 
0-Slot05-06-07-Basic-Logics.pdf
0-Slot05-06-07-Basic-Logics.pdf0-Slot05-06-07-Basic-Logics.pdf
0-Slot05-06-07-Basic-Logics.pdf
 
0-Slot02-Introduction-to-PFC.pdf
0-Slot02-Introduction-to-PFC.pdf0-Slot02-Introduction-to-PFC.pdf
0-Slot02-Introduction-to-PFC.pdf
 
Intro-InstallingTool-FirstProgram
Intro-InstallingTool-FirstProgramIntro-InstallingTool-FirstProgram
Intro-InstallingTool-FirstProgram
 
Background Tasks with Worker Service
Background Tasks with Worker ServiceBackground Tasks with Worker Service
Background Tasks with Worker Service
 
Building Websites Using ASP.NET Core Razor Pages
Building Websites Using ASP.NET Core Razor PagesBuilding Websites Using ASP.NET Core Razor Pages
Building Websites Using ASP.NET Core Razor Pages
 
Dependency Injection in .NET
Dependency Injection in .NETDependency Injection in .NET
Dependency Injection in .NET
 
Asynchronous and Parallel Programming in .NET
Asynchronous and Parallel Programming in .NETAsynchronous and Parallel Programming in .NET
Asynchronous and Parallel Programming in .NET
 
Networking Programming
Networking ProgrammingNetworking Programming
Networking Programming
 
Working with XML and JSON Serializing
Working with XML and JSON SerializingWorking with XML and JSON Serializing
Working with XML and JSON Serializing
 
Building Windows Presentation Foundation (WPF) Application
Building Windows Presentation Foundation (WPF) ApplicationBuilding Windows Presentation Foundation (WPF) Application
Building Windows Presentation Foundation (WPF) Application
 
Course Introduction
Course IntroductionCourse Introduction
Course Introduction
 
Building Windows Presentation Foundation (WPF) Application
Building Windows Presentation Foundation (WPF) ApplicationBuilding Windows Presentation Foundation (WPF) Application
Building Windows Presentation Foundation (WPF) Application
 
Course Introduction
Course IntroductionCourse Introduction
Course Introduction
 

Recently uploaded

Call Girl in Bur Dubai O5286O4116 Indian Call Girls in Bur Dubai By VIP Bur D...
Call Girl in Bur Dubai O5286O4116 Indian Call Girls in Bur Dubai By VIP Bur D...Call Girl in Bur Dubai O5286O4116 Indian Call Girls in Bur Dubai By VIP Bur D...
Call Girl in Bur Dubai O5286O4116 Indian Call Girls in Bur Dubai By VIP Bur D...dajasot375
 
Patrakarpuram ) Cheap Call Girls In Lucknow (Adult Only) 🧈 8923113531 𓀓 Esco...
Patrakarpuram ) Cheap Call Girls In Lucknow  (Adult Only) 🧈 8923113531 𓀓 Esco...Patrakarpuram ) Cheap Call Girls In Lucknow  (Adult Only) 🧈 8923113531 𓀓 Esco...
Patrakarpuram ) Cheap Call Girls In Lucknow (Adult Only) 🧈 8923113531 𓀓 Esco...akbard9823
 
Retail Store Scavanger Hunt - Foundation College Park
Retail Store Scavanger Hunt - Foundation College ParkRetail Store Scavanger Hunt - Foundation College Park
Retail Store Scavanger Hunt - Foundation College Parkjosebenzaquen
 
FULL ENJOY - 9953040155 Call Girls in Shahdara | Delhi
FULL ENJOY - 9953040155 Call Girls in Shahdara | DelhiFULL ENJOY - 9953040155 Call Girls in Shahdara | Delhi
FULL ENJOY - 9953040155 Call Girls in Shahdara | DelhiMalviyaNagarCallGirl
 
Delhi Room Call Girls : ☎ 8527673949, Low rate Call girl service
Delhi Room Call Girls : ☎ 8527673949, Low rate Call girl serviceDelhi Room Call Girls : ☎ 8527673949, Low rate Call girl service
Delhi Room Call Girls : ☎ 8527673949, Low rate Call girl serviceashishs7044
 
Olivia Cox. intertextual references.pptx
Olivia Cox. intertextual references.pptxOlivia Cox. intertextual references.pptx
Olivia Cox. intertextual references.pptxLauraFagan6
 
Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...
Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...
Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...anilsa9823
 
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | DelhiFULL ENJOY - 9953040155 Call Girls in Paschim Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | DelhiMalviyaNagarCallGirl
 
Call Girl Service in Karachi +923081633338 Karachi Call Girls
Call Girl Service in Karachi +923081633338 Karachi Call GirlsCall Girl Service in Karachi +923081633338 Karachi Call Girls
Call Girl Service in Karachi +923081633338 Karachi Call GirlsAyesha Khan
 
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubai
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur DubaiBur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubai
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubaidajasot375
 
Pragati Maidan Call Girls : ☎ 8527673949, Low rate Call Girls
Pragati Maidan Call Girls : ☎ 8527673949, Low rate Call GirlsPragati Maidan Call Girls : ☎ 8527673949, Low rate Call Girls
Pragati Maidan Call Girls : ☎ 8527673949, Low rate Call Girlsashishs7044
 
Jagat Puri Call Girls : ☎ 8527673949, Low rate Call Girls
Jagat Puri Call Girls : ☎ 8527673949, Low rate Call GirlsJagat Puri Call Girls : ☎ 8527673949, Low rate Call Girls
Jagat Puri Call Girls : ☎ 8527673949, Low rate Call Girlsashishs7044
 
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857delhimodel235
 
Russian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts Service
Russian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts ServiceRussian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts Service
Russian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts Servicedoor45step
 
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 60009654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000Sapana Sha
 
Akola Call Girls #9907093804 Contact Number Escorts Service Akola
Akola Call Girls #9907093804 Contact Number Escorts Service AkolaAkola Call Girls #9907093804 Contact Number Escorts Service Akola
Akola Call Girls #9907093804 Contact Number Escorts Service Akolasrsj9000
 
FULL ENJOY - 9953040155 Call Girls in Gtb Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gtb Nagar | DelhiFULL ENJOY - 9953040155 Call Girls in Gtb Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gtb Nagar | DelhiMalviyaNagarCallGirl
 
FULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | DelhiFULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | DelhiMalviyaNagarCallGirl
 
Laxmi Nagar Call Girls : ☎ 8527673949, Low rate Call Girls
Laxmi Nagar Call Girls : ☎ 8527673949, Low rate Call GirlsLaxmi Nagar Call Girls : ☎ 8527673949, Low rate Call Girls
Laxmi Nagar Call Girls : ☎ 8527673949, Low rate Call Girlsashishs7044
 

Recently uploaded (20)

Call Girl in Bur Dubai O5286O4116 Indian Call Girls in Bur Dubai By VIP Bur D...
Call Girl in Bur Dubai O5286O4116 Indian Call Girls in Bur Dubai By VIP Bur D...Call Girl in Bur Dubai O5286O4116 Indian Call Girls in Bur Dubai By VIP Bur D...
Call Girl in Bur Dubai O5286O4116 Indian Call Girls in Bur Dubai By VIP Bur D...
 
Patrakarpuram ) Cheap Call Girls In Lucknow (Adult Only) 🧈 8923113531 𓀓 Esco...
Patrakarpuram ) Cheap Call Girls In Lucknow  (Adult Only) 🧈 8923113531 𓀓 Esco...Patrakarpuram ) Cheap Call Girls In Lucknow  (Adult Only) 🧈 8923113531 𓀓 Esco...
Patrakarpuram ) Cheap Call Girls In Lucknow (Adult Only) 🧈 8923113531 𓀓 Esco...
 
Dxb Call Girls # +971529501107 # Call Girls In Dxb Dubai || (UAE)
Dxb Call Girls # +971529501107 # Call Girls In Dxb Dubai || (UAE)Dxb Call Girls # +971529501107 # Call Girls In Dxb Dubai || (UAE)
Dxb Call Girls # +971529501107 # Call Girls In Dxb Dubai || (UAE)
 
Retail Store Scavanger Hunt - Foundation College Park
Retail Store Scavanger Hunt - Foundation College ParkRetail Store Scavanger Hunt - Foundation College Park
Retail Store Scavanger Hunt - Foundation College Park
 
FULL ENJOY - 9953040155 Call Girls in Shahdara | Delhi
FULL ENJOY - 9953040155 Call Girls in Shahdara | DelhiFULL ENJOY - 9953040155 Call Girls in Shahdara | Delhi
FULL ENJOY - 9953040155 Call Girls in Shahdara | Delhi
 
Delhi Room Call Girls : ☎ 8527673949, Low rate Call girl service
Delhi Room Call Girls : ☎ 8527673949, Low rate Call girl serviceDelhi Room Call Girls : ☎ 8527673949, Low rate Call girl service
Delhi Room Call Girls : ☎ 8527673949, Low rate Call girl service
 
Olivia Cox. intertextual references.pptx
Olivia Cox. intertextual references.pptxOlivia Cox. intertextual references.pptx
Olivia Cox. intertextual references.pptx
 
Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...
Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...
Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...
 
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | DelhiFULL ENJOY - 9953040155 Call Girls in Paschim Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | Delhi
 
Call Girl Service in Karachi +923081633338 Karachi Call Girls
Call Girl Service in Karachi +923081633338 Karachi Call GirlsCall Girl Service in Karachi +923081633338 Karachi Call Girls
Call Girl Service in Karachi +923081633338 Karachi Call Girls
 
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubai
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur DubaiBur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubai
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubai
 
Pragati Maidan Call Girls : ☎ 8527673949, Low rate Call Girls
Pragati Maidan Call Girls : ☎ 8527673949, Low rate Call GirlsPragati Maidan Call Girls : ☎ 8527673949, Low rate Call Girls
Pragati Maidan Call Girls : ☎ 8527673949, Low rate Call Girls
 
Jagat Puri Call Girls : ☎ 8527673949, Low rate Call Girls
Jagat Puri Call Girls : ☎ 8527673949, Low rate Call GirlsJagat Puri Call Girls : ☎ 8527673949, Low rate Call Girls
Jagat Puri Call Girls : ☎ 8527673949, Low rate Call Girls
 
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857
 
Russian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts Service
Russian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts ServiceRussian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts Service
Russian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts Service
 
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 60009654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000
 
Akola Call Girls #9907093804 Contact Number Escorts Service Akola
Akola Call Girls #9907093804 Contact Number Escorts Service AkolaAkola Call Girls #9907093804 Contact Number Escorts Service Akola
Akola Call Girls #9907093804 Contact Number Escorts Service Akola
 
FULL ENJOY - 9953040155 Call Girls in Gtb Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gtb Nagar | DelhiFULL ENJOY - 9953040155 Call Girls in Gtb Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gtb Nagar | Delhi
 
FULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | DelhiFULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | Delhi
 
Laxmi Nagar Call Girls : ☎ 8527673949, Low rate Call Girls
Laxmi Nagar Call Girls : ☎ 8527673949, Low rate Call GirlsLaxmi Nagar Call Girls : ☎ 8527673949, Low rate Call Girls
Laxmi Nagar Call Girls : ☎ 8527673949, Low rate Call Girls
 

Real-Time Communication

  • 2. 2  Understand Real-Time Communication application  Understand the concepts of creating ASP.NET Core with SignalR  Transports  Hubs  Create a simple chat system using ASP.NET Core with SignalR  Work with Entity Framework combined with SignalR 7/21/2022 Objectives
  • 3. 7/21/2022 3 Real Time Web Applications - 1  Traditional Web Approach Real Time Web Applications
  • 4. 7/21/2022 4 Real Time Web Applications - 2  “Real Time” means an immediate response being sent by the Server to the Client.  Real Time is “Pushing” instead of “Pulling”  Push Technology is completely different from Pull Technology. Its about getting told what’s new, instead of asking for what’s new!
  • 5. 7/21/2022 5 Introducing SignalR  SignalR is a library from Microsoft that offers real-time web development for ASP.NET applications.  SignalR is primarily used by applications that require push notifications from server to client (applications such as chat, stock market, gaming, and dashboards).  SignalR solves the problem by providing a persistent connection between the client and the server. SignalR uses the Hubs API to push notifications from server to client, and it supports multiple channels such as WebSocket, server- sent events, and long polling.  SignalR supports multiple clients ranging from C#/C++ to JavaScript.
  • 6. 7/21/2022 6 History of SignalR  SignalR was created in 2011 by David Fowler and Damian Edwards.  SignalR was brought into the ASP.NET project and released as part of ASP.NET in 2013.  SignalR was set up to solve real-time messaging for the Web problem and provide easy support for real-time capabilities on the ASP.NET stack by creating server- and client-side libraries that abstract away the complications of these technologies.
  • 7. 7/21/2022 7 Features of SignalR for ASP.NET Core  SignalR provides an API for creating server-to-client remote procedure calls (RPC). The RPCs call JavaScript functions on clients from server-side .NET Core code.  Handles connection management automatically.  Sends messages to all connected clients simultaneously. For example, a chat room.  Sends messages to specific clients or groups of clients.  Scales to handle increasing traffic.
  • 8. 7/21/2022 8 SignalR high-level architecture  The ASP.NET Core SignalR high-level architecture
  • 9. 7/21/2022 9 SignalR Connections  “SignalR supports "server push" functionality, in which server code can call out to client code in the browser using Remote Procedure Calls (RPC), rather than the request-response model common on the web today.
  • 10. 7/21/2022 10 Transports  SignalR supports the following techniques for handling real-time communication (in order of graceful fallback):  WebSockets  Server-Sent Events  Long Polling  SignalR automatically chooses the best transport method that is within the capabilities of the server and client.
  • 11. 7/21/2022 11 Hubs - 1  SignalR uses hubs to communicate between clients and servers.  A hub is a high-level pipeline that allows a client and server to call methods on each other.  SignalR handles the dispatching across machine boundaries automatically, allowing clients to call methods on the server and vice versa. You can pass strongly-typed parameters to methods, which enables model binding.  SignalR provides two built-in hub protocols:  a text protocol based on JSON  a binary protocol based on MessagePack
  • 12. 7/21/2022 12 Hubs - 2  MessagePack generally creates smaller messages compared to JSON.  Older browsers must support XHR level 2 to provide MessagePack protocol support.  Hubs call client-side code by sending messages that contain the name and parameters of the client-side method.  Objects sent as method parameters are deserialized using the configured protocol.  The client tries to match the name to a method in the client-side code.  When the client finds a match, it calls the method and passes to it the deserialized parameter data.
  • 13. 7/21/2022 13 Hubs - 3  MessagePack is an efficient binary serialization format.  It lets you exchange data among multiple languages like JSON. But it's faster and smaller. Small integers are encoded into a single byte, and typical short strings require only one extra byte in addition to the strings themselves. 
  • 14. 7/21/2022 14 Use hubs in SignalR for ASP.NET Core  The SignalR Hubs API enables you to call methods on connected clients from the server.  In the server code, you define methods that are called by client.  In the client code, you define methods that are called from the server.  SignalR takes care of everything behind the scenes that makes real-time client-to-server and server-to-client communications possible.
  • 15. 7/21/2022 15 Create and use hubs  Create a hub by declaring a class that inherits from Hub, and add public methods to it.  Clients can call methods that are defined as public.
  • 16. 7/21/2022 16 Configure SignalR hubs  The SignalR middleware requires some services, which are configured by calling services.AddSignalR();  When adding SignalR functionality to an ASP.NET Core app, setup SignalR routes by calling endpoint.MapHub in the Startup.Configure method's app.UseEndpoints callback. app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapHub<ChatHub>("/chathub"); });
  • 17. 7/21/2022 17 The Context object - 1  The Hub class has a Context property that contains the properties with information about the connection Property Description ConnectionId Gets the unique ID for the connection, assigned by SignalR. There is one connection ID for each connection. UserIdentifier Gets the user identifier. By default, SignalR uses the ClaimTypes.NameIdentifier from the ClaimsPrincipal associated with the connection as the user identifier. User Gets the ClaimsPrincipal associated with the current user. Items Gets a key/value collection that can be used to share data within the scope of this connection. Data can be stored in this collection and it will persist for the connection across different hub method invocations. Features Gets the collection of features available on the connection. For now, this collection isn't needed in most scenarios, so it isn't documented in detail yet. ConnectionAborted Gets a CancellationToken that notifies when the connection is aborted.
  • 18. 7/21/2022 18 The Context object - 2  Hub.Context also contains the methods Method Description GetHttpContext Returns the HttpContext for the connection, or null if the connection is not associated with an HTTP request. For HTTP connections, you can use this method to get information such as HTTP headers and query strings. Abort Aborts the connection.
  • 19. 7/21/2022 19 The Clients object - 1  The Hub class has a Clients property that contains the following properties for communication between server and client Property Description All Calls a method on all connected clients Caller Calls a method on the client that invoked the hub method Others Calls a method on all connected clients except the client that invoked the method
  • 20. 7/21/2022 20 The Clients object - 2  Hub.Clients also contains the following methods Method Description AllExcept Calls a method on all connected clients except for the specified connections Client Calls a method on a specific connected client Clients Calls a method on specific connected clients Group Calls a method on all connections in the specified group GroupExcept Calls a method on all connections in the specified group, except the specified connections Groups Calls a method on multiple groups of connections OthersInGroup Calls a method on a group of connections, excluding the client that invoked the hub method User Calls a method on all connections associated with a specific user Users Calls a method on all connections associated with the specified users
  • 21. 7/21/2022 21 Send messages to clients  To make calls to specific clients, use the properties of the Clients object. SendMessage() sends a message to all connected clients, using Clients.All. SendMessageToCaller() sends a message back to the caller, using Clients.Caller. SendMessageToGroup() sends a message to all clients in the SignalR Users group.
  • 22. 7/21/2022 22 Strongly typed hubs  A drawback of using SendAsync is that it relies on a magic string to specify the client method to be called.  This leaves code open to runtime errors if the method name is misspelled or missing from the client.  An alternative to using SendAsync is to strongly type the Hub with Hub<T>.
  • 23. 7/21/2022 23 Change the name of a hub method  By default, a server hub method name is the name of the .NET method.  Can use the [HubMethodName] attribute to change this default and manually specify a name for the method.  The client should use this name, instead of the .NET method name, when invoking the method.
  • 24. 7/21/2022 24 Handle events for a connection - 1  The SignalR Hubs API provides the OnConnectedAsync and OnDisconnectedAsync virtual methods to manage and track connections.  Override the OnConnectedAsync virtual method to perform actions when a client connects to the Hub, such as adding it to a group.  Override the OnDisconnectedAsync virtual method to perform actions when a client disconnects. If the client disconnects intentionally (by calling connection.stop(), for example), the exception parameter will be null. However, if the client is disconnected due to an error (such as a network failure), the exception parameter will contain an exception describing the failure.
  • 25. 7/21/2022 25 Handle events for a connection - 2 
  • 26. 7/21/2022 26 Handle errors  Exceptions thrown in your hub methods are sent to the client that invoked the method.  On the JavaScript client, the invoke method returns a JavaScript Promise.  When the client receives an error with a handler attached to the promise using catch, it's invoked and passed as a JavaScript Error object.
  • 27. 7/21/2022 27 Hub filters - 1  Are available in ASP.NET Core 5.0 or later.  Allow logic to run before and after hub methods are invoked by clients.  Work with Hub filter  Create hub filters  Configure hub filters  Use hub filters
  • 28. 7/21/2022 28 Hub filters - 2  Create hub filters  Create a filter by declaring a class that inherits from IHubFilter, and add the InvokeMethodAsync method.  There is also OnConnectedAsync and OnDisconnectedAsync that can optionally be implemented to wrap the OnConnectedAsync and OnDisconnectedAsync hub methods respectively.
  • 30. 7/21/2022 30 Hub filters - 4  Configure hub filters  Hub filters can be applied globally or per hub type.  The order in which filters are added is the order in which the filters run. Global hub filters run before local hub filters.
  • 31. 7/21/2022 31 Hub filters - 5  When writing the filter logic, try to make it generic by using attributes on hub methods instead of checking for hub method names.  Consider a filter that will check a hub method argument for banned phrases and replace any phrases it finds with ***
  • 32. Simple Chat with SignalR
  • 33. 7/21/2022 33 Create simple chat with ASP.NET Core SignalR  Step 1. Create a web project.  Step 2. Add the SignalR client library.  Step 3. Create a SignalR hub.  Step 4. Configure the project to use SignalR.  Step 5. Add code that sends messages from any client to all connected clients.
  • 34. 7/21/2022 34 Step 1. Create a web project. 
  • 35. 7/21/2022 35 Step 2. Add the SignalR client library. 
  • 36. 7/21/2022 36 Step 3. Create a SignalR hub.  A hub is a class that serves as a high-level pipeline that handles client-server communication.  Create a ChatHub.cs  The ChatHub class inherits from the SignalR Hub class. The Hub class manages connections, groups, and messaging.  The SendMessage method can be called by a connected client to send a message to all clients.
  • 37. 7/21/2022 37 Step 4. Configure the project to use SignalR.  The SignalR server must be configured to pass SignalR requests to SignalR.
  • 38. 7/21/2022 38 Step 5. Add code that sends messages  Add code that sends messages from any client to all connected clients
  • 39. 7/21/2022 39 Step 6. Run application 
  • 40. Create an application with Entity Framework and SignalR
  • 41. 7/21/2022 41 Entity Framework combined with SignalR  Step 1. Create Project  Step 2. Work with Entity Framework  Step 3. Create SignalR Hub and configure SignalR  Step 4. Build CRUD functions combined with SignalR  Step 5. Build and run Project. Test all CRUD actions
  • 42. 7/21/2022 42 Step 1. Create Project
  • 43. 7/21/2022 43 Step 2. Work with Entity Framework  Install the following packages from NuGet:  Add “Products.cs” entity and “ApplicationDBContext.cs” classes  Add-Migration and Update-Database  Add ProductsController with Scraffolding
  • 44. 7/21/2022 44 Step 2. Work with Entity Framework - 2
  • 45. 7/21/2022 45 Step 3. Create SignalR Hub and configure  Create SignalR Hubs in the SignalrServer.cs  Add SignalR to Startup.cs
  • 46. 7/21/2022 46 Step 4. CRUD functions with SignalR - 1  Add Client-Side Library to Project  Create a callback function in the script (site.js)  Add the notification to CRUD actions  Add SignalR JavaScript client to View
  • 47. 7/21/2022 47 Step 4. CRUD functions with SignalR - 2  Create a callback function in the script (site.js)
  • 48. 7/21/2022 48 Step 4. CRUD functions with SignalR - 3  Update the list of products in the Create, Edit and Delete functions
  • 49. 7/21/2022 49 Step 5. Build and run Project. Test all actions  Client 1 Client 2
  • 50. Summary  Concepts were introduced:  Real-Time Communication application  Creating ASP.NET Core with SignalR  Transports  Hubs  Create a simple chat system using ASP.NET Core with SignalR  Work with Entity Framework combined with SignalR 50

Editor's Notes

  1. https://caniuse.com/xhr2
  2. https://msgpack.org/
  3. https://docs.microsoft.com/en-us/aspnet/core/signalr/hub-filters?view=aspnetcore-5.0