Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is ASP.NET SignalR?

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "what is ASP.NET SignalR". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Introduction to SignalR

ASP.NET SignalR is a library for ASP.NET developers that simplifies the process of adding real-time web functionality to applications. The real-time Web function makes it possible for the server code to push content to the link client and apply it immediately without requiring the server to wait for the client to request data.

SignalR can be used in any situation where you want to add real-time Web capabilities to ASP.NET applications. Chat rooms are a common example. Users can refresh the Web page to get new data, or the page uses a long poll to retrieve the data. These are all scenarios where SignalR can be applied. Such as dashboards and surveillance systems, real-time games and so on.

SignalR supports the creation of server-to-client remote invocation client Javascript methods in a simple API, and SignalR also includes API and packet connections for connection management.

SignalR automatically handles connection management and allows you to broadcast messages to all connected clients at the same time as a chat room. You can also send messages to specific clients. The connection between the client and the server is persistent and does not need to rebuild every connection like a traditional HTTP connection.

SignalR supports the server push function, where the client code in the browser can be called instead of the request-response mode.

SignalR can be extended to thousands of clients through a service bus, while SignalR is open source and can be accessed using Github.

SignalR and WebSocket

SignalR gives priority to the newer WebSocket transport when WebSocket is available, but it is also compatible with older transports. Although you can write your application in WebSocket right away, using SignalR means you can get a lot of extension methods that you need to implement on your own, and most importantly, you can write code using WebSocket directly in SignalR without having to worry about supporting old clients. At the same time, you don't have to worry about WebSocket updates, as SignalR will be constantly updated to support the basic transport protocol and provide unified interface support for different versions of WebSocket.

Although you can create your solution using WebSocket alone, SignalR supports all the methods you need to write on your own, such as support for other revisions.

Transfer and rollback

SignalR is an abstraction of real-time collaborative transport between some servers and clients. A SignalR connection starts as a HTTP, but if WebSocket is available, it will be utilized. WebSocket is an ideal transport method for SignalR, it can efficiently utilize server-side storage, has the least latency, and has the most basic features (such as full-duplex communication), but it is also strict: WebSocket must require the server to use Windows Server 2012 or windows 8, use the .NET Framework 4.5 framework, if these conditions are not met, SignalR will try to use other transports to create connections.

HTML5 transport protocol

These transfers depend on support for HTML5. If the client does not support the HTML5 standard, use the old transport protocol:

WebSocket: (if the client can support WebSocket on the server side). WebSocket is the only transport protocol that establishes a truly persistent duplex between client and server, but WebSocket also has strict requirements. It is only supported in the latest versions of IE, chrome, and FireFox, and is partially implemented in browsers such as Opera and Safari.

The server sends events: also known as event sources. Event sources are basically supported except for IE.

Comet transports

The following transport protocol is based on the Comet web application model and maintains a long-lasting HTTP request on the client browser or other client, which the server uses to push data without the need for a separate client request.

Persistent framework (Forever Frame): (IE only) persistent framework creates a hidden IFrame that is used to create a request that does not end at the server endpoint, and the server can continuously send scripts to the client to execute scripts, supporting an one-way real-time connection from the server to the client at a time. This link uses a different connection from the client request server, like a standard HTTP request, to create a new connection for each data that needs to be sent.

AJAX long polling (Ajax long polling), which does not create a persistent connection, but instead

Until there is feedback from the other end of the server, when a request is sent to the open server, a new link needs to be established immediately.

Transport protocol selection process

The following list shows SignalR's process of selecting a transport protocol:

1. If the browser is IE8 or older, use long polling

two。 If JSONP is configured (set the jsonp parameter to true when the connection starts), use long polling

3. If you are creating a cross-domain connection (if the SignalR endpoint is not the same as the address on the page), WebSocket will be used if the following conditions are met:

The client supports CORS (for more information, please click here)

The client supports WebSocket

Server-side support for WebSocket

four. If JSONP is not configured and the connection is not cross-domain, if both client and server support WebSocket, WebSocket will be used

5. If neither the client nor the server supports WebSocket, try to use the event source

6. If the server side does not support event sources, use a persistent framework

7. If the persistent framework also fails, use long polling.

Monitoring and transmission

You can decide whether to open logging on the bus and open the browser's console window.

To start your bus event in the browser, add the following command to the client application:

In IE, press F12 to open the developer tools and click the console tab.

In Chrome, use the key combination Ctrl+Shift+J to open the console

Specify the transport protocol

It takes a certain amount of time and server client resources to negotiate the transport protocol. If the client can predict it, then the transport protocol can be specified at the beginning of the connection. The following code uses a short example to open a connection using AJAX long polling if it knows that the client does not support any other protocols:

Connection.start ({transport: 'longPolling'})

You can also specify a callback order for the client to try to specify the transport protocol:

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

The following is the string defined to specify the transport protocol:

WebSockets

ForeverFrame

ServerSentEvents

LongPolling

Connection and Backplane

SignalR API includes two server-side and client-side communication models: persistent connection and bus.

A connection represents a simple endpoint sent by a single recipient, grouped, or broadcast message. Persistent connection API gives programmers direct access to the underlying communication protocols provided by SignalR, using a connection communication model similar to programmers using connection-based API like WCF.

The bus is a higher-level pipeline that is built on a connection-based API that allows the client and server to call methods directly to each other. SignalR magically handles scheduling across machines, making client-side calls to server-side code as simple as calling local methods, and vice versa. Using a bus communication model is similar to using a remote call to API like .NET Remoting, using Backplane allows you to pass strongly typed parameters to methods for model binding.

That's all for "what ASP.NET SignalR is". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report