R
Ry
Can someone explain to me why the following serverlet doesn't stream
Hellos.
require 'webrick'
class Streamlet < WEBrick::HTTPServlet::AbstractServlet
def do_GET(req, res)
res["content-type"] = "text/plain"
r, w = IO.pipe
res.body = r
res.chunked = true
Thread.new do
5.times do |i|
w.write("hello #{i}\n")
sleep(1)
end
w.close
end
end
end
@server = WEBrick::HTTPServer.newPort => 4711)
@server.mount("/stream", Streamlet)
trap("INT") { @server.shutdown }
@server.start
Thank you.
Hellos.
require 'webrick'
class Streamlet < WEBrick::HTTPServlet::AbstractServlet
def do_GET(req, res)
res["content-type"] = "text/plain"
r, w = IO.pipe
res.body = r
res.chunked = true
Thread.new do
5.times do |i|
w.write("hello #{i}\n")
sleep(1)
end
w.close
end
end
end
@server = WEBrick::HTTPServer.newPort => 4711)
@server.mount("/stream", Streamlet)
trap("INT") { @server.shutdown }
@server.start
Thank you.