EventMachine based HTTP Request interface. Supports streaming response processing / based on Zed Shaw's Ragel HTTP
parser.

*installation*

gem1.9.1 install em-http-request

Building native extensions. This could take a while...
Successfully installed em-http-request-0.2.10
1 gem installed
Installing ri documentation for em-http-request-0.2.10...
Updating class cache with 2603 classes...
Installing RDoc documentation for em-http-request-0.2.10...



*testing the client*

1) Launch the websocket server. This example uses the rcscript job 'multicast' e.g.

alias mul="rcscript //job:multicast http://rorbuilder.info/r/websocket.rsf"
mul drobertson secret


2) Execute the code below from an irb session.


require 'em-http'

EventMachine.run {
http = EventMachine::HttpRequest.new("ws://localhost:8080/").get :timeout => 0

http.errback { puts "oops" }
http.callback {
puts "WebSocket connected!"
http.send("Hello client")
}

http.stream { |msg|
puts "Received: #{msg}"
#http.send "Pong: #{msg}"
}
}


3) Observe the received messages in from the irb session e.g.

WebSocket connected!
Recieved: 2 connected!
Recieved: <2>: Hello client
Recieved: jubs_pie: @ViniSaporta HMMMMMMMMMM ME JOGA NA CAMA E ME CHAMA DE RUBY MEU BEM n
Recieved: retrodin: Newbie Questions - Ruby, Pearl, Mits, Please have some patience with me as I am a newbie and don't understand much of the technical jargon
Recieved: agebackwards: Model ex at centre of Ruby break-up - http://www.newzfor.me/?4crd


Resources:
- igrigorik's em-http-request at master [github.com]
- Ruby & WebSockets: TCP for the Browser [igvita.com]

*update: 10-Jul-2010 @ 7:29pm*

Here's the Rcscript job alias:
alias mcl="rcscript //job:multicast_client http://rorbuilder.info/r/websocket.rsf"

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/aQkpvg9BVLc/11867