in clients/ruby/client.rb [11:44]
def listen(url)
ps_thread = Thread.new do
begin
uri = URI.parse(url)
Net::HTTP.start(uri.host, uri.port, :use_ssl => url.match(/^https:/) ? true : false) do |http|
request = Net::HTTP::Get.new uri.request_uri
http.request request do |response|
body = ''
response.read_body do |chunk|
body += chunk
if chunk.end_with? "\n"
event = JSON.parse(body.chomp)
body = ''
if event['stillalive']
print("ping? PONG!\n")
else
do_stuff_with(event)
end
end
end
end
end
rescue Errno::ECONNREFUSED => e
restartable = true
STDERR.puts e
sleep 3
rescue Exception => e
STDERR.puts e
STDERR.puts e.backtrace
end
end
return ps_thread
end