Browse files

Document websockets support

  • Loading branch information...
1 parent d193240 commit 44ded505eec622c5c6f33a0a1c01a20ec2ed32f6 @rubys committed Apr 30, 2012
Showing with 36 additions and 0 deletions.
  1. +35 −0
  2. +1 −0 demo/wiki.rb
@@ -156,6 +156,10 @@ output. This is accomplished by providing one or more of the following:
+ _websocket do
+ code
+ end
Arbitrary Ruby code can be placed in each. Form parameters are made available
as instance variables (e.g., `@name`). Host environment (CGI, Rack, Sinatra)
values are accessible as methods of the `_` object: for example `_.headers`
@@ -286,6 +290,37 @@ output stream, which provides access to other useful methods, for example:
_.print 'foo'
_.printf "Hello %s!\n", 'world'
+Methods provided to Wunderbar.websocket
+WebSocket support requires `em-websocket` to be installed.
+A web socket is a bidrectional channel. `_.send` or `_.push` can be used to
+send arbitrary strings. More commonly, the JSON array methods described above
+can be all be used, the important difference is that the individual entries
+are sent individually and as they are produced.
+`_.recv` or `_.pop` can be used to receive arbitrary strings. More commonly,
+`_.subscribe` is used to register a block that is used as a callback.
+`_.system` will run an aritrary command. Lines of output are sent across the
+websocket as they are received as JSON encoded hashes with two values: `type`
+is one of `stdin`, `stdout` or `stderr`; and `line` which contains the line
+Options to `_websocket` are provided as a hash:
+ * `:port` will chose a port number, with the default being that an
+ available one is picked for you.
+ * `:sync` set to `false` will cause the WebSocket server to be run as a
+ daemon process. This defaults to `true` when run from the command line and
+ to `false` when run as CGI.
+ * `buffer_limit` will limit the amount of entries retained and sent to
+ new clients on open requests. Default is `1`. A value of zero will disable
+ buffering. A value of `nil` will result in unlimited buffering. Note:
+ buffering is effectively unlimited until the first client connects.
Secure by default
@@ -1,6 +1,7 @@
require 'wunderbar'
require 'redcarpet'
require 'digest/md5'
+require 'wunderbar'
Dir.chdir WIKIDATA

0 comments on commit 44ded50

Please sign in to comment.