Canarys | IT Services

Blogs

Introduction on SignalR

,
Share

Introduction on SignalR

Real–Time Web Application

The real-time web is a set of technologies that enable users to receive information as soon as it is published by its authors, rather than requiring that they or their software check a source periodically for updates.

Examples of Real–Time Web Application Development

  • News feed and Notifications in Facebook
  • New updates in Twitter
  • Google Search
  • Google Docs

History of ASP.NET SignalR

Damian Edwards (a program manager on the Microsoft ASP.NET team) was motivated to build a solution for this common problem on Microsoft technologies. SignalR was the answer that started as an open-source project and attracted some other developers as well. Later on, David Fowler (software developer on the Microsoft ASP.NET team) took a serious role in developing this project and has continued to do so.

What Is ASP.NET SignalR?

SignalR is a library on top of the .NET Framework and jQuery (or other client-side technologies) to create real–time web applications by providing application programming interfaces (APIs) that are ready to be used out of the box.

Architecture

Architecture

Transport Options

SignalR relies on transport layers to make communication possible between client(s) and server(s). These four transport layers are categorized in two groups: Comet approaches and modern HTML5 approaches.

  1. Long Polling
  2. Forever Frame
  3. Server-Sent Event
  4. WebSockets

How ASP.NET SignalR Uses Transports

The ASP.NET SignalR JavaScript library has a built-in mechanism that switches between approaches in priority based on their availability. Unless you specify one or more transport options to be used, the following order of options is considered:

  1. WebSockets
  2. Server-sent event
  3. Forever Frame
  4. Long polling

Creating a sample SignalR Application

1. Create a new ASP.NET MVC Web Application using Visual Studio.

2. Add SignalR libraries using the NuGet Package Manager. 

NuGet Package Manager

 

3. Click on Install which downloads and adds the required SignalR libraries into the project.

Install SignalR

 

4. After the assemblies are installed, you have to create an endpoint. Create a folder called PersistentConnections.

PersistentConnection Folder

 

5. Add a class called SamplePersistentConnection.cs in the PersistentConnections folder. Add the code into the class as below.

Sample Persistent Connection Class

 

6. Add Startup.cs class if it is missing in the project and update the code as below.

Startup Class

 

7. Add index.html page to the project.

8. Add the below code to the head section of the html page.

Head Section

 

9. Add the below code to the body section of the html page

 

.Body Section

10. Open two instances of the browser and browse for the application. The message sent is immediately available to all the clients.

Chat Application

 

References

1. http://www.asp.net/signalr

2. http://www.codeproject.com/Tips/590660/Introduction-to-SignalR

3. http://www.c-sharpcorner.com/UploadFile/82b980/introduction-to-signal-r/

4. https://github.com/SignalR/SignalR/wiki

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Reach Us

With Canarys,
Let’s Plan. Grow. Strive. Succeed.