[ANN] Sunshowers - Web Sockets for Ruby, Rack+Rainbows!

Eric Wong normalperson at yhbt.net
Sun Dec 13 18:43:20 EST 2009

Sunshowers is a Ruby library for Web Sockets.  It exposes an easy-to-use
API that may be used in both clients and servers.  On the server side,
it is designed to work with Rack::Request and Rainbows! concurrency
models that expose a synchronous application flow.  On the client side,
it may be used as a standalone wrapper for IO-like objects.

* http://rainbows.rubyforge.org/sunshowers/
* sunshowers at librelist.com
* git://git.bogomips.org/sunshowers.git

It appears works well with the echo_client.py example shipped with
pywebsocket.  It has not been tested against normal web browsers, though
there's no reason it shouldn't work.

== Features

* supports reads and writes of both UTF-8 and binary Web Socket frames

* compatible with Revactor, Rainbows::Fiber::IO and core Ruby IO objects

* pure Ruby implementation, should be highly portable, tested under 1.9

== Install

You may download the tarball from the Rainbows! project page on Rubyforge
and run setup.rb after unpacking it:


You may also install it via RubyGems on Gemcutter:

  gem install sunshowers

== Usage

Make sure you're using one of the following concurrency models
for Rainbows!:

* FiberSpawn
* FiberPool
* Revactor
* ThreadSpawn
* ThreadPool

  # A simple echo server example
  require "sunshowers"
  use Rack::ContentLength
  use Rack::ContentType
  run lambda { |env|
    req = Sunshowers::Request.new(env)
    if req.ws?
      ws_io = req.ws_io
      ws_io.each do |record|
        break if record == "Goodbye"
      req.ws_quit! # Rainbows! should handle this quietly
    [404, {}, []]

Already using a Rack::Request-derived class?  Sunshowers::WebSocket may
also be included in any Rack::Request-derived class, so you can just
open it up and include it:

  class Sinatra::Request < Rack::Request
    include Sunshowers::WebSocket

See the examples/ directory in the source tree for a client example.

Eric Wong

More information about the rainbows-talk mailing list