Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > WEBrick listening on multiple ports?

Reply
Thread Tools

WEBrick listening on multiple ports?

 
 
Lloyd Zusman
Guest
Posts: n/a
 
      11-07-2004
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
http://www.velocityreviews.com/forums/(E-Mail Removed)
God bless you.



 
Reply With Quote
 
 
 
 
David G. Andersen
Guest
Posts: n/a
 
      11-07-2004
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: (E-Mail Removed) me: (E-Mail Removed)
MIT Laboratory for Computer Science http://www.angio.net/


 
Reply With Quote
 
 
 
 
Lloyd Zusman
Guest
Posts: n/a
 
      11-07-2004
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 <(E-Mail Removed)> 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
> (E-Mail Removed)
> God bless you.
>
>
>


--
Lloyd Zusman
(E-Mail Removed)
God bless you.



 
Reply With Quote
 
Lloyd Zusman
Guest
Posts: n/a
 
      11-07-2004
"David G. Andersen" <(E-Mail Removed)> 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
(E-Mail Removed)
God bless you.



 
Reply With Quote
 
Stefan Arentz
Guest
Posts: n/a
 
      11-07-2004
Lloyd Zusman <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
WEBrick: Has anyone used WEBrick::Session? Lloyd Zusman Ruby 2 02-21-2013 06:49 PM
Start multiple listening servers in one file Thomas W Python 1 01-16-2009 05:59 PM
WEBrick::Daemon and WEBrick Aaron Smith Ruby 2 03-18-2007 03:47 AM
Multiple scripts accessing one WEBrick session? Naren Ruby 2 08-12-2006 03:03 PM
Interruptions in live news listening Realone Player listening Thaqalain Computer Support 6 07-16-2005 02:11 PM



Advertisments