# Sunshowers - Web Sockets for Ruby, Rack+Rainbows!

**URL:** <https://www.ruby-forum.com/t/sunshowers-web-sockets-for-ruby-rack-rainbows/180169>\
**Category:** Ruby\
**Created:** [December 14, 2009, 12:43am UTC](https://www.ruby-forum.com/t/sunshowers-web-sockets-for-ruby-rack-rainbows/180169 "2009-12-14T00:43:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/97f17d/32.png) [@ericw](https://www.ruby-forum.com/u/ericw)\
**Post date:** [December 14, 2009, 12:43am UTC](https://www.ruby-forum.com/t/sunshowers-web-sockets-for-ruby-rack-rainbows/180169/1 "2009-12-14T00:43:58Z")

</div>

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/](http://rainbows.rubyforge.org/sunshowers/)
- removed\_email\_address@domain.invalid
- 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:

[http://rubyforge.org/frs/?group\_id=8977](http://rubyforge.org/frs/?group_id=8977)

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

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  
end

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

---

<div class="post-metadata">

**Author:** ![ericw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/97f17d/32.png) [@ericw](https://www.ruby-forum.com/u/ericw)\
**Post date:** [December 14, 2009, 2:11am UTC](https://www.ruby-forum.com/t/sunshowers-web-sockets-for-ruby-rack-rainbows/180169/2 "2009-12-14T02:11:13Z")

</div>

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/](http://rainbows.rubyforge.org/sunshowers/)
- removed\_email\_address@domain.invalid
- git://git.bogomips.org/sunshowers.git

Changes:

This release contains a small bugfix to generate the  
WebSocket-Location headers correctly. Thanks to Lakshan Perera  
for the report and fix.

---

<div class="post-metadata">

**Author:** ![ericw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/97f17d/32.png) [@ericw](https://www.ruby-forum.com/u/ericw)\
**Post date:** [December 14, 2009, 12:12pm UTC](https://www.ruby-forum.com/t/sunshowers-web-sockets-for-ruby-rack-rainbows/180169/3 "2009-12-14T12:12:52Z")

</div>

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/](http://rainbows.rubyforge.org/sunshowers/)
- removed\_email\_address@domain.invalid
- git://git.bogomips.org/sunshowers.git

Changes:

The ws\_handshake! method now accepts optional headers, as  
cookies should be settable during the handshake process. Header  
rules are exactly the same as normal Rack response headers and  
typically a Hash with String keys and newline-delimited values.

Sunshowers::IO#gets now discards binary frames as dictated by  
the current IETF draft specification (66). Setting  
Sunshowers::IO#keep\_binary=true will revert to the old (and  
hopefully future) behavior on a per-object basis. Do not expect  
the +keep\_binary+ member of Sunshowers::IO Struct to become part  
of the a stable API.
