Server-Sent-Events with Celluloid and Reel
There's a lot of buzz around websockets, and rightly so. They provide very powerful, two-way communication between you and the user's browser. Sadly, the current level of compatibility, along with the Flash-based fallbacks, leave me shuddering at the thought of using them in almost every scenario.
More recently, the half-a-websocket alternative server-sent-events (SSE), has been getting a fair amount of press, too. Aaron Patterson (aka, @tenderlove) showed us how to do it using ActionController::Live in Rails 4. Even better, Tony Arcieri (aka @bascule) has an example of how to use websockets within his brilliant project Celluloid and its offshoot webserver, Reel.
Thanks goes entirely to these two giants of the Ruby community, I've simply patched their work together to show a simplistic example of how to do a SSE broadcast using a Reel webserver and Aaron's basic SSE class.
The Code
As you might imagine, SSE probably serves the needs of most everyone that wants to push up events and data to a browser. Thankfully, SSE is based on http and there are a handful of pure-javascript polyfills available. Check out MDN for more information on SSE.
Thanks for reading! Tweet at me with any comments, suggestions, or questions. Check back later or follow me to see when I share how I'm using this with Ember.js.