ASP. net mvc SignalR (1): Background, mvcsignalr

Source: Internet
Author: User

ASP. net mvc SignalR (1): Background, mvcsignalr

Series Directory: ASP. net mvc SignalR

Keywords: HTTP, round robin, WebSocket, Server-Sent Events, long polling, forever frame.

 

 

1. HTTP

HTTP (HyperText Transfer Protocol) is a language used to "talk" between Web application clients and servers.

HTTP operations are based on the request-response mode. This mode usually starts when a client initiates a request. In addition, the request-response mode is also called the pull mode: when the client needs to access resources on the server, it initiates a connection to the server, use the information required for the "language" request defined by HTTP. The server processes the request and returns the requested resources from the client, and immediately closes the connection. Each time the client needs to obtain a new resource, this process will be repeated.

It can be seen that the entire HTTP operation is a synchronization process: after a request is sent to the server, the client will be forced to wait; Before the server responds, it will do nothing. Even with Ajax technology, this operation mode uses and complies with the HTTP protocol and client-driven request-response mode. The client is always the active party and determines when to connect to the server. However, in real-time communication, the server must be the active party and can send information to the client at any time without explicitly requesting the client. Therefore, in some cases, HTTP is not very effective.

 

2. Round Robin

When we need the server itself to become the party that sends messages to the client as the master node, the first solution we should think of is "Round Robin ". "Round Robin" usually refers to periodic connections through the client. It regularly checks whether there are some related updates on the server, and still uses the HTTP pull (pull) mode.

Advantages:

    • Easy to implement
    • Applicable to any situation and all servers and browsers

Disadvantages:

    • Frequent connection and disconnection
    • The number of connections will increase in proportion to the number of clients

In short, although the round-robin implementation consumes resources, it is a good choice if it is applied to situations where frequent updates are not required.

 

3. Push

Since the application using the HTTP pull (pull) mode is not very efficient, naturally you need to push (push) mode (server push.

1) WebSocket

The WebSocket standard includes a set of development APIs, which are defined by W3C (World Wide Web Consortium). In addition, the communication protocol is defined by IETF (Internet Engineering Task Force, internet Engineering team) is responsible for formulating.

Basically, WebSocket allows the establishment of persistent connections. Such connections are enabled when the client needs them and remain open. Therefore, a two-way channel is created between the client and the server. Through this two-way channel, either party can send information to the other party at any time.

Disadvantages:

    • The browser does not implement all WebSocket Functions
    • The server also needs to support WebSocket

But there is no doubt that WebSocket technology can be used to implement the real-time push service in the future.

2) Server-Sent Events

Server-Sent Events, also known as API Event Source, is the second standard being developed by the W3 alliance. However, this standard is currently in the Candidate recommendation status. It is a relatively simple Javascript API and does not need to modify the underlying protocol. It is easier to implement and use than WebSocket standards.

Compared with WebSocket, Server-Sent Events creates a one-way channel from the Server to the client, but the client opens this channel. In other words, the client subscribes to an available event source from the server. when data is sent through this channel, the client receives the notification.

All communications are performed over HTTP. Compared with some more traditional connection methods, the only difference is that Content-Type text/event-stream is used in the response, which indicates that the connection will remain open, it is used to send continuous event streams or messages from the server.

Advantages:

    • Almost all browsers currently support this standard (except IE and some specific mobile browsers)

Disadvantages:

    • The Content-Type used must be parsed.
    • A one-way channel is established between the server and the client. If the client needs to send data to the server, it must establish a different connection to complete the process. This will involve more resource overhead than WebSocket.

 

4. HTTP-based push

1) Long polling

This push technology is very similar to the round robin mentioned above, but it has also made some improvements to improve communication efficiency and timeliness.

In this case, the client also polls updates, but unlike polling, the connection will not be automatically closed if no data is available and will be initiated again later. In long polling, the connection remains open until an event is reported on the server.

There are only two reasons for closing the connection initiated by the client:

A. the server sends data to the client through connection

B. timeout error due to idle connection

In both cases, a new connection will be established immediately and will wait for the update again.

This connection is specially used to receive data from the server. If the client needs to send data up, it will open an HTTP connection dedicated to receiving data from the server in parallel.

Advantages:

    • Low latency when updating the client
    • The number of opened and closed connections is reduced, and the resource usage is lower than that of polling
    • No special browser is required. HTTP provides sufficient functions.

Disadvantages:

    • Resource consumption is higher than other technologies that only open one connection
    • There may be some latency between notifications

2) forever frame

Forever frame cleverly uses the HTML <IFRAME> label to establish a permanent and open connection. To some extent, this is very similar to Server-Sent Events.

Forever frame requires a <IFRAME> tag on the client page. The URL in the tag source is used to specify the server being monitored. The server keeps the connection open permanently and calls the script function defined on the client to send updates through the connection. To some extent, we may say that this technology mainly depends on the streaming script executed on the client at the time of receiving ).

Advantages:

    • High Resource Utilization
    • Excellent real-time performance

Disadvantages:

    • Complex Application
    • High memory usage
    • Other connections are also required when the client sends data to the server.

 

5. What we need is not only push

In an asynchronous, multi-user, and real-time application environment, pushing is only an indispensable part. To develop these systems that are always pleasing to the eye, more functions and features are required:

    • Users who manage connections: the server must know which users are connected to the service and which users are disconnected. In addition, you must control the number of clients.
    • Manage subscription: the server must be able to manage subscriptions or group users who receive specific types of messages.
    • Receiving and Processing Operations: the server can not only send information to the client in real time, but also dynamically receive and process information.
    • Monitors information submission: provides separate mechanisms related to Message Queuing and information submission management to ensure that all clients can be updated.
    • Provides flexible and easy-to-use APIs for multiple clients

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.