[WEBrick] streaming output

Discussion in 'Ruby' started by Dan Janowski, Nov 29, 2004.

  1. Dan Janowski

    Dan Janowski Guest

    Is there a way to send a stream of output while processing, I want to
    send ongoing status? The basic response construct seems to want the
    output in a finalized form. The clients will render progressively from
    what I understand.

    Dan
     
    Dan Janowski, Nov 29, 2004
    #1
    1. Advertising

  2. Dan Janowski

    GOTOU Yuuzou Guest

    In message <>,
    `Dan Janowski <>' wrote:
    > Is there a way to send a stream of output while processing, I want to
    > send ongoing status? The basic response construct seems to want the
    > output in a finalized form. The clients will render progressively from
    > what I understand.


    Set an IO to res.body, and write data from another thread.

    require "webrick"

    class Streamlet < WEBrick::HTTPServlet::AbstractServlet
    def do_GET(req, res)
    res["content-type"] = "application/octet-stream"
    r, w = IO.pipe
    res.body = r
    Thread.start{
    10.times{|i|
    w.write("#{i}" * 4096)
    sleep(1)
    }
    w.close
    }
    end
    end

    httpd = WEBrick::HTTPServer.new:)Port=>10080)
    httpd.mount("/", Streamlet)
    trap:)INT){ httpd.shutdown }
    httpd.start

    --
    gotoyuzo
     
    GOTOU Yuuzou, Nov 29, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lloyd Zusman
    Replies:
    2
    Views:
    432
  2. Phlip

    Webrick streaming bodies

    Phlip, Sep 10, 2005, in forum: Ruby
    Replies:
    4
    Views:
    213
    Phlip
    Sep 14, 2005
  3. Aaron Smith

    WEBrick::Daemon and WEBrick

    Aaron Smith, Mar 9, 2007, in forum: Ruby
    Replies:
    2
    Views:
    340
    Aaron Smith
    Mar 18, 2007
  4. Ry

    streaming with webrick

    Ry, Apr 1, 2007, in forum: Ruby
    Replies:
    2
    Views:
    223
  5. samba
    Replies:
    1
    Views:
    300
    samba
    Sep 15, 2008
Loading...

Share This Page