📒
Notes
Cloud ComputingData Science/AIGame Development
  • Home
  • Big O
  • Data Structures & Algorithms
    • Data Structures
      • Array
      • Stack
      • Queue
      • Linked List
      • Binary Tree
    • Algorithms
      • Searching
      • Sorting
      • Graphs
        • Searching
        • Minimum Spanning Tree
        • Shortest Path Algorithms
      • String Algorithms
  • Object Oriented Programming
  • Languages
    • HTML/CSS
      • CSS
    • C++
    • C#
      • Types
      • Keywords
        • Modifiers
          • Access Modifiers
        • Method Parameters
      • Operators and Expressions
      • Collections
      • Constructors
      • Delegates
      • Indexers
      • Concepts
      • Features
        • LINQ
          • Operators
          • Working with Data
          • Methods
          • Resources
        • Asynchronous Programming
        • Reflection
    • Dart
    • GraphQL
    • JavaScript
      • Variable and Parameter
      • Built-in objects
        • Array
        • Built-in Functions
      • Functions
      • Classes
      • Prototype
      • Libraries
        • jQuery
        • React
          • Components
          • State and Lifecycle
          • Hooks
            • useState
            • useEffect
          • Resources
      • Testing Framework
      • Web APIs
    • Kotlin
      • Basics
    • Python
      • Basics
      • Data Structures
      • Functions
      • Resources
        • Flask
    • SQL
      • Basics
      • Operators
      • JOINs
      • Aggregations
      • Subqueries
      • Views
      • Functions
        • Window Functions
      • Stored Procedures
      • Performance Tuning
      • Extras
    • Resources
  • 🌐Web Frameworks
    • Angular
      • Templates
      • Directives
        • Attribute Directives
        • Structural Directives
    • ASP.NET
      • Fundamentals
        • Dependency Injection
        • Middleware
        • Session & State Management
      • Web apps
        • MVC
          • Controllers
            • Filters
          • Models
            • Model Binding
            • Model Validation
          • Views
            • Tag Helpers
            • View Components
          • Features
        • Client-side development
      • Web APIs
        • Controller-based APIs
        • Minimal APIs
        • OpenAPI
        • Content Negotiation
      • SignalR
      • Host and Deploy
        • IIS
      • Security
    • Django
      • The Request/Response Cycle
    • Terminologies
      • Web Server
        • Internet Information Services
    • Resources
  • 📱App Frameworks
    • Introduction
      • Resources
    • Xamarin
      • Lifecycle
      • Custom Renderers & Effects
      • Behaviors
      • Triggers
      • Gestures
      • Commands
      • Dependency Service in XF
      • Libraries
      • Showcase
    • .NET MAUI
      • Controls
      • Navigation
      • Storage Options
  • Multi-Platform Frameworks
    • .NET
      • .NET Framework
        • ADO.NET
        • WCF
      • Fundamentals
        • Logging
        • Testing
      • Advanced
        • Asynchronous Programming
        • Parallel Programming
        • Threading
        • Memory Management
          • Garbage Collection
    • Flutter
  • Object-Relational Mappers
    • Entity Framework
      • Application Models
      • Configuration
      • Setting Up
      • Advanced
  • Databases
    • Introduction
      • DBMS Architecture
      • Normalization
      • Database Transaction Models
    • Relational Databases
      • Microsoft SQL Server
        • Basics
        • Functions
        • Stored Procedures
        • Error Handling
        • Log Shipping
        • Querying and Manipulating JSON data
        • Statements
        • Topics
        • Extras
    • Non-Relational Databases
      • MongoDB
      • Redis
        • Data Structures
        • Introduction
        • Managing Database
  • Tools
    • Version Control
      • Git
        • Setup and Config
        • Basics
          • Sharing and Updating Projects
        • Resources
      • Perforce Helix
    • GitHub
    • Powershell
  • Software Development
    • Software Development Life Cycle
    • Software Design Patterns
      • GoF Design Patterns
      • Architectural Patterns
        • MVC
        • MVVM
        • N-tier Architecture
        • Onion Architecture
        • Data Transfer Objects
      • CQRS
    • Software Design Principles
      • S.O.L.I.D. Priniciple
  • System Design
    • Topics
      • Load Balancing
  • Topics
    • JWT
    • Caching
      • Static vs Dynamic Caching
    • OSI model
      • HTTP
    • Glossary
    • API
      • SOAP
      • REST
    • Microservices
    • WebHooks
    • Practice
    • Operating Systems
      • Windows
    • Architecture
  • 🔖Bookmarks
  • 🔗Resources
Powered by GitBook
On this page
  • What is SignalR?
  • How does SignalR works?
  • Why use SignalR?
  • Long Polling
  • Forever Frame
  • Event Source
  • Web sockets
  • SignalR
  • Installing

Was this helpful?

  1. 🌐Web Frameworks
  2. ASP.NET

SignalR

PreviousContent NegotiationNextHost and Deploy

Last updated 8 months ago

Was this helpful?

What is SignalR?

  • SignalR provides the consistent or persistent connection between the server and the client.

  • It is used to develop real-time applications.

  • it bridges the gap between the server and the client so the information can flow in and out in real-time without any restriction or barrier.

  • it is bi-directional meaning server can send data to the client and vice versa.

  • Eg. Chat Applications, Social Applications.

How does SignalR works?

  • SignalR uses only one of the four components / technologies.

    Web sockets -> Event Source -> Forever Frame -> Long Polling

  • First it goes to Web Sockets if not available then Event Source and so on as it goes further towards the end the communication efficiency between server and client decreases.

Why use SignalR?

  • implementing SignalR means getting all the 4 components in a single package.

  • if any of the 4 components gets any updates, SignalR is gonna handle those and make the application work as it was expected to do.

  • SignalR is an abstraction means we don't have to go into details how it works.

  • it is cross-application compatible and easy to use.

  • it can be used to make broadcast groups.

  • scalable

AJAX

  • AJAX provides the server validation and it can also check for the new data.

  • It is not an open/persistent connection .

Long Polling

  • AJAX requests the server for the new data if it got any and keep on requesting.

  • While Long Polling will request the server once for any new data that the client request, the server will keep the request as soon as it gets the data it will respond.

  • Disadvantage

    • simulates the persistent connection

    • one way means server cannot act on its own behind there is always request from client

Forever Frame

  • it uses IFrame

  • server pushes the data to the client

  • Disadvantages

    • high memory usage

    • client should support IFrames

    • one-way persistent connection means from server to client.

Event Source

  • it uses content-type (text/event-stream)

  • one-way persistent connection means server to client

  • asynchronous

  • think of it as subscribe option when you subscribe to the channel you get the updates not the another way around

Web sockets

  • bi-directional persistent connection

  • multiuser

  • full -duplex - communication between server and client can happen at the same time

  • asynchronous

SignalR

  • inherits the Hub class

  • RPC (Remote Procedure Call)

    • server can call the functions at client side and vice versa

  • Hubs vs Persistent Connections

    • Hubs are at higher level than Persistent Connections

    • both of these are classes which can be inherited

    • Persistent Connection get instantized when connection is established and stays persistent until connection is closed. While Hubs are instantized for every new request.

Installing

StartUp.cs
app.mapSignalR();
ConfigureAuth(app);
_Layout.cshtml
<script src="~/Scripts/jquery.signalR-2.2.0.min.js></script>
<script src="~/signalr/js"></script> //this will be created 

@RenderSection("scripts", required: false)
SignalR.js
$.connection.hub.start()
    .done(function(){ 
        console.log("")
        $.connection.myHub.server.Announce("Connected");
    })
    .fail(function(){ alert() })
    
    
@.connection.myHub.client.Announce = function(message){alert(message)}
public class MyHub: Hub{
    public void Announce(string message){
        Clients.All.Announce(message);
    }
}   
LogoReal-time ASP.NET with SignalR | .NETMicrosoft