tags : HTTP, Web Development, WebSockets, WebRTC

FAQ

  • AJAX + XMLHTTPRequest (Also can use JSON) : no longer popularly used
  • FetchAPI
  • WebSockets

Does Websockets use Eventsource

No.

What’s Chunked Transfer Encoding

  • text based
  • See Chunked transfer encoding - Wikiwand
  • SSE uses Chunked transfer encoding if using HTTP1.1 else in 2 that’s not needed.
    • with HTTP2, binary framing layer that handles message fragmentation natively. so no need of chunked encoding.
  • Chunked transfer encoding makes sense when you don’t know the size of your output ahead of time, and you don’t want to wait to collect it all to find out before you start sending it to the client.
    • apply to stuff like serving the results of slow database queries

HTTP1.1 & HHTP2 support

  • HTTP/1.1: 6 SSE connections per browser per domain limit
  • HTTP/2: 100 SSE connections per browser per domain limit
  • NOT a replacement for WebSockets
    • SSE does not support messages back from the client to the server.
    • You can however do full duplex w SSE(S->C) and RESTAPI(C->S), but that’s a hack.
    • Usually SSE easier to setup than Websockets

What?

  • Introduced 2004
  • SSEs are sent via the normal HTTP protocol
  • MIME type for SSE is text/event-stream
  • Server Push implementation enabling a client to receive automatic updates from a server via an HTTP connection
  • Usage
    • Send message updates/data streams to a browser client
    • Client uses JavaScript API EventSource, to recieve the event stream
    • Can run outside of browser context too

Main mechanisms

  • content-type:text/eventstream
  • HTTP1.1: chunked transfer encoding
  • chunk transfer encoding

Implementation