librelist archives

« back to archive

Fwd: [ANN/RFC] LMGTWTY - Web Sockets for Rack+Rainbows!

Fwd: [ANN/RFC] LMGTWTY - Web Sockets for Rack+Rainbows!

From:
Eric Wong
Date:
2009-12-13 @ 09:12
Some updates I posted to the rack-devel ML:

From: Eric Wong <normalperson@yhbt.net>
To: rack-devel@googlegroups.com
Subject: Re: [ANN/RFC] LMGTWTY - Web Sockets for Rack+Rainbows!

Eric Wong <normalperson@yhbt.net> wrote:
> For reading, Lmgtwty::IO#gets() returns a single web socket frame.
> So it removes the first and last bytes of (\x00 frame \xff)

Lmgtwty::IO#gets now also understands the binary framing format,
too.  This does not appear to be generated by Chrome or pywebsocket,
but both understand it.

> For writing, Lmgtwty::IO#write(buf) - writes the contents of +buf+ to
> the client socket, transparently framing it with "\x00" and "\xff"
> bytes.

Lmgtwty::IO#write(buf) will now call either Lmgtwty::IO#write_utf8(buf)
or Lmgtwty::IO#write_binary(buf) depending on the encoding of +buf+

write(buf) will attempt to use write_utf8(buf) since that seems to be
the prevalent framing, under 1.9 just make sure +buf+ is of
Encoding::UTF_8.

> === Lmgtwty::Request is a subclass of Rack::Request
> 
> It adds a few helper methods to handle handshaking and using
> Lmgtwty::IO.

I've moved all the logic into a Lmgtwty::WebSocket module, so
users of other Rack::Request subclasses (like Sinatra::Request)
can also get that stuff included as they wish.

> * iobuffer is a C extension gem dependency, I expect replacing it with
>   a pure Ruby Array of Strings with minimal/no performance loss since
>   the Strings are expected to be short anyways.

The iobuffer dependency is gone with no noticeable performance hit.  If
you're writing valid UTF-8 (and encoding strings as such under 1.9),
then performance has actually improved now (especially if you use
write_utf8 directly).

> * I've only tested this with the python command-line client.  I
>   avoid GUIs as much as possible and using Chrome at this stage
>   (without a Vimperator equivalent) would cause me too much pain.

At least now I've read the Chrome WebSockets code.