我有以下基于 EventMachine 的 Ruby 客户端,但是当它连接到服务器时没有任何输出:
EventMachine.run do
conn = EventMachine::HttpRequest.new('http://localhost:10000')
http = conn.get
http.stream do |data|
puts data # THIS SHOULD BE OUTPUTTING SOMETHING
end
trap("INT") { puts 'INT'; http.close; EventMachine.stop }
trap("TERM") { puts 'TERM'; http.close; EventMachine.stop }
end
和服务:
module Simulation
class QuoteService < EM::Connection
def post_init
puts "CONNECTION ESTABLISHED" # THIS DOES OUTPUT
EventMachine.add_periodic_timer(1) do
puts "test data" # THIS DOES OUTPUT
send_data("test data")
end
end
end
end
EventMachine.run do
Signal.trap("INT") { EventMachine.stop }
Signal.trap("TERM") { EventMachine.stop }
EventMachine.start_server('0.0.0.0', 10000, Simulation::QuoteService)
end
我认为该服务有问题。任何想法为什么客户什么都不输出?