Long-polling, Websockets, SSE (server-sent Event), the difference between WebRTC

Source: Internet
Author: User

In the following example, the client refers to a browser, and the server refers to a Web server host.

To better understand these points of knowledge, you should simply understand how a typical HTTP site works.

Normal http:
    1. Client requests Web page from server side
    2. The server responds accordingly
    3. The server returns the corresponding to the client

AJAX Polling:
    1. The client requests the Web page from the server side using normal HTTP methods
    2. The client executes the JavaScript polling script in the Web page, periodically sending requests to the server (such as sending a request every 5 seconds) to obtain information
    3. The server responds to each request and returns the appropriate information, just like a normal HTTP request

AJAX long-polling:

HTML5 Server Sent Events (SSE)/EventSource:
  1. The client requests the Web page from the server side using normal HTTP methods
  2. The client executes a JavaScript script in the Web page that establishes a connection to the server
  3. When there is a valid update on the server side, an event is sent to the client
    • Real-time push of server-to-client data, most of which is what you need
    • You need a server that can do event loops
    • Cross-domain connections are not allowed
    • If you feel that this is not enough, to learn more, you can refer to the following documents and manuals
      Using server-sent Events
      https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events
      Server-sent Events
      http://html5doctor.com/server-sent-events
      Stream Updates with Server-sent Events
      http://www.html5rocks.com/en/tutorials/eventsource/basics/
      TUTORIAL:JSF 2 and HTML5 Server Sent Events
      http://jaxenter.com/tutorial-jsf-2-and-html5-server-sent-events-42932.html

HTML5 Websockets:
  1. The client requests the Web page from the server side using normal HTTP methods
  2. The client executes a JavaScript script in the Web page that establishes a connection to the server
  3. Between the server and the client, you can send valid data to each other in two directions
    • The server can send data to the client in real time, and the client can send the data to the server in real time.
    • You need a server that can do event loops
    • Using WebSockets to allow connections to be established across domains
    • It also supports third-party websocket host servers, such as pusher or others. This way you only need to care about the implementation of the client, reducing the development difficulty.
    • If you feel that this is not enough, to learn more, you can refer to the following documents and manuals
      An Introduction to WebSockets
      http://www.developerfusion.com/article/143158/an-introduction-to-websockets/
      Writing WebSocket Client Applications
      Https://developer.mozilla.org/en-US/docs/WebSockets/Writing_WebSocket_client_applications
      Start Using HTML5 WebSockets Today
      http://code.tutsplus.com/tutorials/start-using-html5-websockets-today--net-13270
WebRTC:

WEBRTC is a point-to-point type of transmission that supports a variety of transport protocols, such as UDP, TCP, or even abstraction layer protocols. It was designed with the same consideration for allowing the transmission of data in two ways, reliable and unreliable. This technology is generally used in the transmission of large amounts of data, such as audio, video and other streaming media.

Comet:

Comet is a web-enabled push technology that enables the server to deliver updated information to the client in real time without requiring the client to make a request, and there are currently two implementations, long polling and IFRAME streams. If you want to learn more, you can refer to Wikipedia or IBM

Event Loop
Event loop is a program structure that waits for and sends messages and events.
Long polling
A
long poll is a way to persist after a connection is opened, waiting for the server to push the data back down.
IFrame Stream

The IFRAME stream is to insert a hidden iframe in the page, using its SRC attribute to create a long link between the server and the client, and the server transmits the data to the IFRAME (usually HTML, the JavaScript that is responsible for inserting the information) to update the page in real time.

The advantage of IFRAME streaming is that browsers are compatible, and Google uses IFRAME streams in some products, such as Google Talk.


Source: http://www.pureasme.com/blog/2014/0422419.html


From for notes (Wiz)

Long-polling, Websockets, SSE (server-sent Event), the difference between WebRTC

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.