[SignalR Learning Series] 1. SignalR theory introduction, signalr Theory

Source: Internet
Author: User

[SignalR Learning Series] 1. SignalR theory introduction, signalr Theory
What is SignalR?

ASP. NET SignalR is a development library that allows ASP. NET developers to easily add instant messaging functions to their programs. The instant messaging function can send data directly from the server to the online client without waiting for the client to request data to return data.

SignalR provides a simple api to create remote engineering call protocol (RPC) for the server -- client. You can use the C # code on the server to call javascript Functions (or other platforms) on the browser ). SignalR also provides APIs for connection management and Group connection management.

 

SignalR and WebSocket

If both the client and server support WebSocket, SignalR transmits data through WebSocket. Of course, you can also use WebSocket to implement the SignalR function. However, if you use SignalR, you do not need to consider the problem of WebSocket not supported by the client or server.

 

Protocol selection for SignalR

SignalR is the abstraction and implementation of several protocols that allow instant communication between the client and the server. A SignalR connection is initiated through an http request and then escalated to WebSocket (if both the client and the server support it ). WebSocket is the most ideal protocol for SignalR. It can effectively use the memory of the server, with the lowest latency and the most basic features (such as full-duplex connections between the client and the server ), however, it also has strict requirements. It is also required to use Windows Server 2012 or a Windows 8 or above on the Server.. NET Framework 4.5 .. If these requirements are not met, SignalR uses other protocols to establish a connection.

HTML 5 Protocol

The following two protocols are based on HTML5. If the client does not support HTML5, other protocols will be used for communication.

Comet Protocol

The following two protocols are based on the Comet model.

SignalR protocol selection process

The following list shows how to select the specific protocol used by SignalR.

Monitoring Protocol

You can enable logging on your Hub to monitor what protocols your SignalR uses.

You need to add the following code to your client code

$.connection.hub.logging = true;

Protocol

The SignalR judgment Protocol also consumes a certain amount of client and server resources. If you know the protocols supported by the client and server, you can specify a protocol to establish a connection.

For example, if you know that the client only supports long polling, you can specify to use long polling for communication.

connection.start({ transport: 'longPolling' });

You can also specify a sequence for the client to communicate in the sequence. The function of the following code is to use WebSocket first. If it fails, long polling is used.

connection.start({ transport: ['webSockets','longPolling'] });

SignalR contains the following four specified protocol constants:

  • WebSockets
  • ForeverFrame
  • ServerSentEvents
  • LongPolling

 

Connection and Hubs

The SignalR api establishes two models for communication between the client and the server: persistent connections and Hubs.

A persistent connection represents an endpoint that can send a single receiver, Group receiver, or broadcast information. APIS for persistent connection are APIs provided by SignalR to developers for accessing low-level protocols. The connection model is similar to that of WCF.

Hubs is a high-level api provided by SignalR. It allows clients and servers to call each other's methods on their own side. The Hubs model is similar to. Net Remoting. Using Hubs also allows you to pass strong parameters for model binding.

SignalR Architecture

The following structure diagram shows the connection between Hubs, persistent connection, and the underlying protocol used by SignalR.

How Hubs works

When the server code calls the client method, an information package is transmitted through the current protocol, which contains the name and parameters of the called method (if the parameter is an object, json serialization will be used ). The client will match the method name. If the client has a method called by the server, the client will substitute the parameter data and execute the method.

You can use Fiddler or other tools to track method calls.

The following figure shows a SignalR call record captured by Fiddler. The method is called through a Hub called MoveShapeHub, and the client method name to be executed is updateShape.

In this example, the H parameter is the Hub name and the M parameter, while the method parameter data is the parameter.

How to Select Communication Models

In most cases, the Hub api is used for communication. The connection api is used in the following situations.

  • The model that forces the specified message sending.
  • Compared with the remote scheduling model, developers prefer message transmission and scheduling models.
  • The original application used message scheduling, and now the interface needs to use SignalR.

 

Server Requirements

Operating System

The SignalR component can run on Win7, Windows Server 2008 R2, and higher-level systems. To support WebSocket, use Win8, Windows Server 2012, and more advanced systems.

IIS version

  • IIS 8 or IIS 8 Express and more advanced versions.
  • IIS 7 and 7.5. Extensionless URLs is required.
  • IIS must be in integrated mode and does not support classic models. If the Server-Sent Events protocol is used in Classic mode, the delay may exceed 30 seconds.
  • The Host Program must run at a fully trusted level.

 

Client Requirements

Browser

Protocol Internet Explorer Chrome (Windows or iOS) Firefox Safari (OSX or iOS) Android
WebSockets 10 + Current-1 Current-1 Current-1 N/
Server-Sent Events N/ Current-1 Current-1 Current-1 N/
ForeverFrame 8 + N/ N/ N/ 4.1
Long Polling 8 + Current-1 Current-1 Current-1 4.1

 

 

 

 

 

Windows desktop and Silverlight

Protocol . NET application Silverlight
Web Sockets Windows 8 + and. NET 4.5 + N/
Forever Frame N/ N/
Server-Sent Events . NET 4 + 5 +
Long Polling . NET 4 + 5 +

 

 

 

 

 

Windows Store and Windows Phone

Protocol Windows Store/. NET Windows Store/JavaScript Windows Phone/IE Windows Phone/. NET
WebSockets N/ Win8 + 8 + N/
Forever Frame N/ Win8 + 7.5 + N/
Server-Sent Events Win8 + N/ N/ 8 +
Long Polling Win8 + Win8 + 7.5 + 8 +

 

Reference link:

Https://docs.microsoft.com/zh-cn/aspnet/signalr/overview/getting-started/introduction-to-signalr

Https://docs.microsoft.com/zh-cn/aspnet/signalr/overview/getting-started/supported-platforms

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.