Sorry at first. My English is not good....
I am trying Server Sent Events in Rails4 (Ruby on Rails).
sse_controller.rb
def test_sse
response.headers['Content-Type'] = 'text/event-stream'
sse = SSE.new(response.stream)
puts 'New SSE = '+sse.to_s
begin
loop do
sse.write({ nowtimes: Time.new}, event: 'timer')
end
ensure
sse.close
end
end
mypage.html.erb
$(document).ready(function(){
var evtSource = new EventSource("/sse/test_sse");
evtSource.addEventListener('timer', function(e) {
obj = JSON.parse(e.data);
console.log(obj.nowtimes);
});
})
I use NGINX as my web server.
While I used Passenger as my app server. It's work good but can't support multi-thread. It's only can open 6 Tabs at the same time.
While I try PUMA as my app server, It's work strangely. SSE in client is trying reconnect uninterrupted.
If I use Passenger, how should I resolve the problem about number of connection?
Or if I use PUMA, how should I resolve the loop about reconnect?