/usr/share/doc/ruby-em-http-request/examples/websocket-handler.rb is in ruby-em-http-request 0.3.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | require 'rubygems'
require 'lib/em-http'
module KBHandler
include EM::Protocols::LineText2
def receive_line(data)
p "Want to send: #{data}"
p "Error status: #{$http.error?}"
$http.send(data)
p "After send"
end
end
EventMachine.run {
$http = EventMachine::HttpRequest.new("ws://localhost:8080/").get :timeout => 0
$http.disconnect { puts 'oops' }
$http.callback {
puts "WebSocket connected!"
}
$http.stream { |msg|
puts "Recieved: #{msg}"
}
EM.open_keyboard(KBHandler)
}
|