igrigorik/em-http-request — Issue #164: WebSockets support?
Author: arvicco
Created: 2012-01-14 21:49:03+00:00
State: open

In the previous versions of em-http-request (0.2.7 I believe) a following method of communication through WebSockets was recommended:
--------
WebSocket example. Bi-directional communication with WebSockets: simply pass in a ws:// resource and the client will negotiate the connection upgrade for you. On successfull handshake the callback is invoked, and any incoming messages will be passed to the stream callback. The client can also send data to the server at will by calling the “send” method!

EventMachine.run {
http = EventMachine::HttpRequest.new("ws://yourservice.com/websocket").get :timeout => 0

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

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

In the latest gem (1.0.1), this code does not work, as http.send("Hello client") raises:
undefined method `Hello client' for # (NoMethodError)

Is WebSockets support in em-http-request 1.0.1 broken, or am I missing something here?