My Understanding of HTTP Polling, Long Polling, HTTP Streaming and WebSockets

前端 未结 4 988
猫巷女王i
猫巷女王i 2020-12-12 09:13

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 implem

4条回答
  •  不思量自难忘°
    2020-12-12 09:17

    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.

提交回复
热议问题