HTTP Polling, Long Polling, HTTP Streaming and WebSockets

I have read many posts on SO and the web regarding the keywords in my question title and learned a lot from them. Some of the questions I read are related to specific implementation challenges while others focus on general concepts. I just want to make sure I understood all of the concepts and the reasoning why technology X was invented over technology Y and so on. So here goes:

Http Polling: Basically AJAX, using XmlHttpRequest.

Http Long Polling: AJAX but the server holds on to the response unless the server has an update, as soon as the server has an update, it sends it and then the client can send another request. Disadvantage is the additional header data that needs to be sent back and forth causing additional overhead.

Http Streaming: Similar to long polling but the server responds with a header with "Transfer Encoding: chunked" and hence we do not need to initiate a new request every time the server sends some data (and hence save the additional header overhead). The drawback here is that we have to "understand" and figure out the structure of the data to distinguish between multiple chunks sent by the server.

Java Applet, Flash, Silverlight: They provide the ability to connect to socket servers over tcp/ip but since they are plugins, developers don‘t want to depend on them.

WebSockets: they are the new API which tries to address the short comings of above methods in the following manner:

  • The only advantage of WebSockets over plugins like Java Applets, Flash or Silverlight is that WebSockets are natively built into browsers and does not rely on plugins.
  • The only advantage of WebSockets over http streaming is that you don‘t have to make an effort to "understand" and parse the data received.
  • The only advantage of WebSockets over Long Polling is that of elimination of extra headers size & opening and closing of socket connection for request.

Are there any other significant differences that I am missing? I‘m sorry if I am re-asking or combining many of the questions already on SO into a single question, but I just want to make perfect sense out of all the info that is out there on SO and the web regarding these concepts.

There are more differences than the ones you have identified.

Duplex/directional:

  • Uni-directional: HTTP poll, long poll, streaming.
  • Bi-direcitonal: WebSockets, plugin networking

In order of increasing latency (approximate):

  • WebSockets
  • Plugin networking
  • HTTP streaming
  • HTTP long-poll
  • HTTP polling

CORS (cross-origin support):

  • WebSockets: yes
  • Plugin networking: Flash via policy request (not sure about others)
  • HTTP * (some recent support)

Native binary data (typed arrays, blobs):

  • WebSockets: yes
  • Plugin networking: not with Flash (requires URL encoding across ExternalInterface)
  • HTTP *: recent proposal to enable binary type support

Bandwidth in decreasing efficiency:

  • Plugin networking: Flash sockets are raw except for initial policy request
  • WebSockets: connection setup handshake and a few bytes per frame
  • HTTP streaming (re-use of server connection)
  • HTTP long-poll: connection for every message
  • HTTP poll: connection for every message + no data messages

Mobile device support:

  • WebSocket: iOS 4.2 and up. Some Android via Flash emulation or using Firefox for Android or Google Chrome for Android which both provide native WebSocket support.
  • Plugin networking: some Android. Not on iOS
  • HTTP *: mostly yes

Javascript usage complexity (from simplest to most complicated). Admittedly complexity measures are somewhat subjective.

  • WebSockets
  • HTTP poll
  • Plugin networking
  • HTTP long poll, streaming

Also note that there is a W3C proposal for standardizing HTTP streaming called Server-Sent Events. It is currently fairly early in it‘s evolution and is designed to provide a standard Javascript API with comparable simplicity to WebSockets.

原文地址:https://www.cnblogs.com/liangmou/p/8328443.html

时间: 2024-08-29 17:58:10

HTTP Polling, Long Polling, HTTP Streaming and WebSockets的相关文章

Bosh vs Comet vs Long Polling vs Polling

最近在研究在中国特色移动互联网下通过性最好的应用层协议办法,看到很多混乱的概念和实现,54chen在对各种名词的历史进行了深度考察,特作记录以做区分. HTTP协议历史 第一个HTTP协议诞生于1989年3月. 第一个HTTP协议的版本是HTTP 0.9,它的组成极其简单,因为它只允许客户端发送GET这一种请求. HTTP协议的第二个版本是HTTP 1.0,直到HTTP 1.0成为最重要的面向事务的应用层协议.该协议对每一次请求/响应,同样是建立并关闭一次连接. HTTP协议的第三个版本是HTT

使用 WebSockets 进行 HTML5 视频直播

最近在做的一个小项目需要用到相关技术,找到这篇文章貌似不错,于是就翻译转载上来了. Recently I'm interesting in these technologies and I'm working on a project related to it. I've found this useful article so I translated and posted it here. 原文地址 / Original post: HTML5 Live Video Streaming v

Spring MVC 3.2 Preview: Techniques for Real-time Updates

Last updated on November 5th, 2012 (Spring MVC 3.2 RC1) In my last post I introduced the new Servlet 3 based, async support in Spring MVC 3.2 and talked about long-running requests. A second very important motivation for async processing is the need

springmvc(18)使用WebSocket 和 STOMP 实现消息功能

[0]README 1)本文旨在 介绍如何 利用 WebSocket 和 STOMP 实现消息功能: 2)要知道, WebSocket 是发送和接收消息的 底层API,而SockJS 是在 WebSocket 之上的 API:最后 STOMP(面向消息的简单文本协议)是基于 SockJS 的高级API (干货--简而言之,WebSocket 是底层协议,SockJS 是WebSocket 的备选方案,也是 底层协议,而 STOMP 是基于 WebSocket(SockJS) 的上层协议) 3)b

Spark整合kafka0.10.0新特性(二)

接着Spark整合kafka0.10.0新特性(一)开始 import org.apache.kafka.clients.consumer.ConsumerRecord import org.apache.kafka.common.serialization.StringDeserializer import org.apache.spark.streaming.kafka010._ import org.apache.spark.streaming.kafka010.LocationStrat

Microsoft.AspNet.SignalR 2.2

Nuget :http://www.nuget.org/packages/Microsoft.AspNet.SignalR/ What is SignalR? ASP.NET SignalR is a library for ASP.NET developers that simplifies the process of adding real-time web functionality to applications. Real-time web functionality is the

Bayeux协议

Bayeux 协议-- Bayeux 1.0草案1 本备忘录状态 This document specifies a protocol for the Internet community, and requests discussion and suggestions for improvement. This memo is written in the style and spirit of an IETF RFC but is not, as of yet, an official IE

Android开发训练之第五章第三节——Transferring Data Without Draining the Battery

Transferring Data Without Draining the Battery GET STARTED DEPENDENCIES AND PREREQUISITES Android 2.0 (API Level 5) or higher YOU SHOULD ALSO READ Optimizing Battery Life In this class you will learn to minimize the battery life impact of downloads a

vue使用远程在线更新代码

main.js import Vue from 'vue'import App from './App'import router from './router'import Vuex from 'vuex'import store from './store'import axios from 'axios'import VueAwesomeSwiper from 'vue-awesome-swiper'import 'swiper/dist/css/swiper.css'// import