Detailed Comet server Push and SIGNALR

Source: Internet
Author: User
Tags requires socket silverlight

HTTP protocol is a typical request/response protocol, is based on TCP/IP above an application layer protocol, the most typical feature of this Protocol is stateless and requires the client to launch the request server to response, which means that the server can not actively "push Information But many modern application requirements such as "service-side push", such as monitoring systems, pricing systems, games, collaborative documents, progress bars and other applications. Therefore, this article will talk about the different methods of server push technology, and how the SIGNALR in asp.net encapsulates these details to achieve the purpose of push.

Some means of implementing server push

Because the HTTP protocol does not support Full-duplex, the current approach to server "Push" is based on the characteristics of the HTTP protocol. But it can be broadly divided into high-end atmospheric full-duplex classes and a slightly tricky long polling class. Streaming classes usually have a lot of restrictions, such as the browser version requirements, the need to use sliverlight or flash, etc. to achieve full-duplex. Long polling classes consist primarily of long polling or uninterrupted Ajax requests.

Ajax Periodic Request method

This approach is not strictly a server push, but the client in a relatively short interval of time to the server to use AJAX request information, if the server side has a new event, the client will be acquired on the next request, and the client calls the corresponding callback function to process this information. The simple schematic diagram is shown in Figure 1.

Figure 1. Ajax Recurring Requests

Of course, some of the drawbacks of this approach are also obvious, the first periodic request will consume server resources in vain, and secondly, this approach is not real "real-time."

The way of long connection

A long connection is another way to suspend an extra AJAX request for a page, return the request to the client when an event occurs, and suspend a long connection here. This avoids the loss of periodic requests, as shown in Figure 2.

Figure 2. Long connection mode

The disadvantage of this approach is also evident in the need for both the client and the server to write custom implementation code for this part of the functionality.

Use plug-in mode

Using plug-ins such as Silverlight and Flash can be based on sockets for Full-duplex communication, but this way requires a specific client, Cross-platform is not good (such as mobile phone client, etc. do not support a number of plug-ins, the PC side is not pre-installed Silverlight, etc.). Restrictions on the conditions are more stringent.

Forever IFrame

This way in essence and long connection method is very similar to embed an IFRAME element in the page, the SRC attribute of the element points to the requested object, the server has an event occurred, on the return of a call client JS method js. The transfer-encoding Property of the HTTP header in the IFRAME is chunked, which means that the server does not know how much data to send to the client, and implicitly implies that the length of the connection is infinite.

HTML5 Web Socket

WebSocket is a network technology for Full-duplex communication between browsers and servers that HTML5 has started to provide. The WebSocket communication protocol was set as standard RFC 6455,websocketapi by the IETF in 2011.

In the WebSocket API, the browser and the server only need to do a handshake action, then, between the browser and the server formed a fast channel. The data can be transmitted directly between the two.

The advent of the WebSocket protocol avoids the use of server resources and broadband usage in these ways. But it is also obvious that there are certain requirements for both the client and the server, including the version of the browser and the version of the servers (e.g. iis7.5+)

Signalr?

There are so many ways to implement real-time applications, as the ASP.net framework provides a framework called SIGNALR to encapsulate these network details, and SIGNALR automatically chooses the appropriate implementation technology to implement the real-time program. We need to focus on a higher level of business implementation without having to focus on the technical implementation details.

The SIGNALR needs to be based on jquery 1.6.4, at least on the server side. Net FrameWork 4.0+.

Using SIGNALR automatically chooses the appropriate network implementation details based on the environment, which is defined by Microsoft's website as follows:

If the browser is IE8 or less than IE8, use a long connection method.

If the JSONP parameter is configured, the long connection method is used.

If a cross-domain request is requested and the web socket is supported on both the client and server side, and the client supports cors, the web socket is used

If there is no cross-domain, both the client and the browser support, use the web socket method

If the client or server side does not support Web sockets, it will use the HTML5 server-sent events

If Server-sent event is not supported, the Forever IFrame will be used

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.