WEBrick listening on multiple ports?

Discussion in 'Ruby' started by Lloyd Zusman, Nov 7, 2004.

  1. Lloyd Zusman

    Lloyd Zusman Guest

    I'm writing an application that requires a specialized HTTP server.
    This server needs to listen on a range of ports, for example, ports
    10000 through 10100. Whenever someone makes an HTTP connection to the
    host on any of these ports, a WEBrick servlet will respond. The same
    servlet should respond to each connection.

    I know that I can do this using the "hammer and tongs" method of
    starting up a large number of identical WEBrick applications, each
    configured to listen on a different port. But I'd like to do this
    within a single program instance, if at all possible.

    It's trivial to do this with a single port, but is there a way to use
    WEBrick to listen on a range of ports in this manner? If so, could
    someone point me to an example or some docs?

    Although I prefer WEBrick, if there's an easy way to do manage a range
    of HTTP connections like this using some other ruby utility, I'll settle
    for that.

    Thanks in advance.

    --
    Lloyd Zusman

    God bless you.
    Lloyd Zusman, Nov 7, 2004
    #1
    1. Advertising

  2. On Sun, Nov 07, 2004 at 09:26:48AM +0900, Lloyd Zusman scribed:
    > It's trivial to do this with a single port, but is there a way to use
    > WEBrick to listen on a range of ports in this manner? If so, could
    > someone point me to an example or some docs?


    brick = HTTPServer.new(...)

    myports.each { |p| brick.listen(address, p) }

    Works like a charm.

    -Dave

    --
    work: me:
    MIT Laboratory for Computer Science http://www.angio.net/
    David G. Andersen, Nov 7, 2004
    #2
    1. Advertising

  3. Lloyd Zusman

    Lloyd Zusman Guest

    P.S. -- In my request below, I'm hoping to be able to do this without
    forking off a bunch of threads, one for each HTTPServer instance
    associated with a different port. I thought that I might be
    able to have a single HTTPServer instance and use the #listen
    method inherited from GenericServer, but I can't seem to get
    that to work. Thanks again in advance.


    Lloyd Zusman <> writes:

    > I'm writing an application that requires a specialized HTTP server.
    > This server needs to listen on a range of ports, for example, ports
    > 10000 through 10100. Whenever someone makes an HTTP connection to the
    > host on any of these ports, a WEBrick servlet will respond. The same
    > servlet should respond to each connection.
    >
    > I know that I can do this using the "hammer and tongs" method of
    > starting up a large number of identical WEBrick applications, each
    > configured to listen on a different port. But I'd like to do this
    > within a single program instance, if at all possible.
    >
    > It's trivial to do this with a single port, but is there a way to use
    > WEBrick to listen on a range of ports in this manner? If so, could
    > someone point me to an example or some docs?
    >
    > Although I prefer WEBrick, if there's an easy way to do manage a range
    > of HTTP connections like this using some other ruby utility, I'll settle
    > for that.
    >
    > Thanks in advance.
    >
    > --
    > Lloyd Zusman
    >
    > God bless you.
    >
    >
    >


    --
    Lloyd Zusman

    God bless you.
    Lloyd Zusman, Nov 7, 2004
    #3
  4. Lloyd Zusman

    Lloyd Zusman Guest

    "David G. Andersen" <> writes:

    > On Sun, Nov 07, 2004 at 09:26:48AM +0900, Lloyd Zusman scribed:
    >> It's trivial to do this with a single port, but is there a way to use
    >> WEBrick to listen on a range of ports in this manner? If so, could
    >> someone point me to an example or some docs?

    >
    > brick = HTTPServer.new(...)
    >
    > myports.each { |p| brick.listen(address, p) }
    >
    > Works like a charm.


    I had tried that, but I must have used an invalid 'address' or something
    ... 'cause now it works.

    Thanks!

    --
    Lloyd Zusman

    God bless you.
    Lloyd Zusman, Nov 7, 2004
    #4
  5. Lloyd Zusman <> writes:

    > P.S. -- In my request below, I'm hoping to be able to do this without
    > forking off a bunch of threads, one for each HTTPServer instance
    > associated with a different port. I thought that I might be
    > able to have a single HTTPServer instance and use the #listen
    > method inherited from GenericServer, but I can't seem to get
    > that to work. Thanks again in advance.


    Depending on the operating system that you deploy on, you can also do this
    with simple port mapping in the firewall. On linux I use this to map port
    localhost:8080 to external-address:80.

    S.
    Stefan Arentz, Nov 7, 2004
    #5
    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. Replies:
    3
    Views:
    357
    CBFalconer
    Jul 5, 2005
  2. Thomas W
    Replies:
    1
    Views:
    271
  3. mreister
    Replies:
    1
    Views:
    3,150
    mreister
    May 25, 2010
  4. Lloyd Zusman
    Replies:
    2
    Views:
    388
  5. Aaron Smith

    WEBrick::Daemon and WEBrick

    Aaron Smith, Mar 9, 2007, in forum: Ruby
    Replies:
    2
    Views:
    304
    Aaron Smith
    Mar 18, 2007
Loading...

Share This Page