0
我有以下基于EventMachine的德胜客户端,但没有输出,当它连接到服务器:流套接字服务与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
我认为这项服务有些不正确。任何想法为什么客户端输出什么?
嘿乍得..我面临着类似的问题,我的流叽叽喳喳api ..你找到解决方案吗? –
嗨@RahulDess,不幸我不记得了。然而,我确实运行了一个WebSocket服务,你可以在这里看到它(https://github.com/chaddjohnson/trading_websocket_service/blob/master/config.ru)和[here](https:// github。 COM/chaddjohnson/trading_websocket_service /斑点/主/ LIB/web_socket_service.rb)。 –