# server-sent events ### another weird HTTP thang Patrick Mueller - [`@pmuellr`](https://twitter.com/pmuellr) - [`muellerware.org`](http://muellerware.org) developer advocate for IBM's [Bluemix](http://bluemix.net) PaaS .smaller[.smaller[
(all slides) ]]
--- layout: true
server-sent events
{{content}}
--- ### wat * aka `EventSource` aka `text/event-stream` resources * like a one-way WebSocket, HTTP server to client * **much** simpler protocol than WebSocket * [W3C Server-Sent Events specification](http://www.w3.org/TR/eventsource/) * more info: ["Stream Updates with Server-Sent Events" at WebPlatform.org](http://docs.webplatform.org/wiki/tutorials/eventsource_basics) --- ### server ```js //!snippet: server.js ``` --- ### client ```js //!snippet: client.js ```
the server sent: 'the time is Mon Sep 22 2014 23:36:46 GMT-0400 (EDT)'
* "typed" events (type is a string) `source.addEventHandler("time-message", ...)` * auto-reconnect, and "open and ""error" events --- ### however ... ### * no "close" or "readystatechange" events * everywhere **BUT** IE and android < 4.4 * see [caniuse.com's Server-sent DOM events page](http://caniuse.com/#feat=eventsource) * polyfills available: * [Yaffle/EventSource](https://github.com/Yaffle/EventSource/) * [remy/polyfills](https://github.com/remy/polyfills/blob/master/EventSource.js) * [rwaldron/jquery.eventsource](https://github.com/rwaldron/jquery.eventsource) --- class: center, middle # `fin`