Title / Description
Code require 'rubygems' require 'em-http' def subscribe(opts) listener = EventMachine::HttpRequest.new('http://cm1.subg.ru/listen?cid='+ opts[:channel]).get :head => opts[:head] listener.callback { puts "Listener recieved: " + listener.response + "\n" modified = listener.response_header['LAST_MODIFIED'] subscribe({:channel => opts[:channel], :head => {'If-Modified-Since' => modified}}) } end EventMachine.run { channel = "pub" EM.add_periodic_timer(5) do time = Time.now publisher = EventMachine::HttpRequest.new('http://cm1.subg.ru/publish?id='+channel).post :body => "Hello @ #{time}" publisher.callback { puts "Published message @ #{time}" puts "Response code: " + publisher.response_header.status.to_s puts "Headers: " + publisher.response_header.inspect puts "Body: \n" + publisher.response puts "\n" } end subscribe(:channel => channel) subscribe(:channel => channel) }
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code