Skip to content

Instantly share code, notes, and snippets.

@bka
Created March 16, 2011 10:12
Show Gist options
  • Save bka/872279 to your computer and use it in GitHub Desktop.
Save bka/872279 to your computer and use it in GitHub Desktop.
websocket client example
require 'rubygems'
require 'em-http-request'
require 'active_support'
EventMachine.run {
$http = EventMachine::HttpRequest.new("ws://localhost:8080/").get :timeout => 0
$http.errback { |e| puts "oops #{e}" }
$http.callback {
puts "WebSocket connected!"
$http.send("server_version");
$http.send("user_online");
}
$http.stream { |msg|
puts "Got: #{msg}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment