# Integrated Webserver?

**URL:** <https://rubytalk.org/t/integrated-webserver/7550>\
**Category:** ruby-talk\
**Created:** [21 August 2003 16:54 UTC](https://rubytalk.org/t/integrated-webserver/7550 "2003-08-21T16:54:09Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_DeMello1](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@Martin\_DeMello1](https://rubytalk.org/u/Martin_DeMello1)\
**Post date:** [21 August 2003 16:54 UTC](https://rubytalk.org/t/integrated-webserver/7550/1 "2003-08-21T16:54:09Z")

</div>

The HTML form thread made me wonder if we shouldn’t have some equivalent  
of Perl’s IndigoPerl: [http://www.indigostar.com/indigoperl.htm](http://www.indigostar.com/indigoperl.htm)

How hard would such a thing be to integrate with the WindowsInstaller?

martin

---

<div class="post-metadata">

**Author:** ![Laurent\_Julliard4](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@Laurent\_Julliard4](https://rubytalk.org/u/Laurent_Julliard4)\
**Post date:** [21 August 2003 19:55 UTC](https://rubytalk.org/t/integrated-webserver/7550/2 "2003-08-21T19:55:09Z")

</div>

did you noticed that webrick exists and is now part of the standard  
distribution?

cut&pasted code from [webrick.org](http://webrick.org)  
#http server  
#!/usr/local/bin/ruby  
require ‘webrick’  
include WEBrick

s = HTTPServer.new(  
:Port =\> 2000,  
:DocumentRoot =\> Dir::pwd + “/htdocs”  
)

## mount subdirectories

s.mount(“/ipr”, HTTPServlet::FileHandler, “/proj/ipr/public\_html”)  
s.mount(“/~gotoyuzo”,  
HTTPServlet::FileHandler, “/home/gotoyuzo/public\_html”,  
true) #\<= allow to show directory index.

> **···**
>
> il Thu, 21 Aug 2003 16:44:19 GMT, Martin DeMello [martindemello@yahoo.com](mailto:martindemello@yahoo.com) ha scritto::
> 
> > The HTML form thread made me wonder if we shouldn’t have some equivalent  
> > of Perl’s IndigoPerl: [http://www.indigostar.com/indigoperl.htm](http://www.indigostar.com/indigoperl.htm)

---

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Joel\_VanderWerf1](https://rubytalk.org/u/Joel_VanderWerf1)\
**Post date:** [21 August 2003 22:04 UTC](https://rubytalk.org/t/integrated-webserver/7550/3 "2003-08-21T22:04:38Z")

</div>

gabriele renzi wrote:

> #http server  
> #!/usr/local/bin/ruby  
> require ‘webrick’  
> include WEBrick
> 
> s = HTTPServer.new(  
> :Port =\> 2000,  
> :DocumentRoot =\> Dir::pwd + “/htdocs”  
> )

Looks nice. I tried this example (with minor modifications) and got

[2003-08-21 14:44:46] INFO WEBrick 1.3.1  
[2003-08-21 14:44:46] INFO ruby 1.8.0 (2003-08-04) [i686-linux]  
[2003-08-21 14:44:47] WARN TCPServer Error: Address family not  
supported by protocol - socket(2)

Could it be because I’m trying to run it inside a 192.\* network? (Tried  
googling for that error message, but that didn’t help much.)

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello1](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@Martin\_DeMello1](https://rubytalk.org/u/Martin_DeMello1)\
**Post date:** [21 August 2003 22:35 UTC](https://rubytalk.org/t/integrated-webserver/7550/4 "2003-08-21T22:35:38Z")

</div>

Very neat! I admit that I didn’t know exactly what webrick was; I’d just  
assumed that since no one mentioned a pure ruby http server in the other  
thread, there wasn’t an easy-to-use one available.

martin

> **···**
>
> gabriele renzi [surrender\_it@remove.yahoo.it](mailto:surrender_it@remove.yahoo.it) wrote:
> 
> > il Thu, 21 Aug 2003 16:44:19 GMT, Martin DeMello \> [martindemello@yahoo.com](mailto:martindemello@yahoo.com) ha scritto::
> > 
> > > The HTML form thread made me wonder if we shouldn’t have some equivalent  
> > > of Perl’s IndigoPerl: [http://www.indigostar.com/indigoperl.htm](http://www.indigostar.com/indigoperl.htm)
> > 
> > did you noticed that webrick exists and is now part of the standard  
> > distribution?

---

<div class="post-metadata">

**Author:** ![Joe\_Cheng](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@Joe\_Cheng](https://rubytalk.org/u/Joe_Cheng)\
**Post date:** [22 August 2003 05:36 UTC](https://rubytalk.org/t/integrated-webserver/7550/5 "2003-08-22T05:36:44Z")

</div>

> did you noticed that webrick exists and is now part of the standard  
> distribution?

I didn’t know about webrick. That is SO FRICKIN’ COOL.

---

<div class="post-metadata">

**Author:** ![Laurent\_Julliard4](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@Laurent\_Julliard4](https://rubytalk.org/u/Laurent_Julliard4)\
**Post date:** [21 August 2003 23:35 UTC](https://rubytalk.org/t/integrated-webserver/7550/6 "2003-08-21T23:35:43Z")

</div>

dunno if it could possibly get confused, this it’s working fine for  
me:

require ‘webrick’  
include WEBrick

s = HTTPServer.new(  
:Port =\> 2000,  
:DocumentRoot =\> “/”  
)

s.mount(“/my”, HTTPServlet::FileHandler, ‘C:\pubs’,true)

s.start

it seems that you could try passing  
:BindAddress =\>your\_chosen\_addr

possibly you have multiple net interface and this confuses the script?

or maybe you could contact the author to check if you discovered a bug  
🙂

> **···**
>
> il Fri, 22 Aug 2003 07:04:38 +0900, Joel VanderWerf [vjoel@PATH.Berkeley.EDU](mailto:vjoel@PATH.Berkeley.EDU) ha scritto::
> 
> > [2003-08-21 14:44:46] INFO WEBrick 1.3.1  
> > [2003-08-21 14:44:46] INFO ruby 1.8.0 (2003-08-04) [i686-linux]  
> > [2003-08-21 14:44:47] WARN TCPServer Error: Address family not  
> > supported by protocol - socket(2)
> > 
> > Could it be because I’m trying to run it inside a 192.\* network?

---

<div class="post-metadata">

**Author:** ![Dan\_North](https://avatars.discourse-cdn.com/v4/letter/d/2bfe46/32.png) [@Dan\_North](https://rubytalk.org/u/Dan_North)\
**Post date:** [22 August 2003 16:35 UTC](https://rubytalk.org/t/integrated-webserver/7550/7 "2003-08-22T16:35:46Z")

</div>

Joe Cheng wrote:

> > did you noticed that webrick exists and is now part of the standard  
> > distribution?
> 
> I didn’t know about webrick. That is SO FRICKIN’ COOL.

It just gets more and more ridiculous doesn’t it?

I’m back to writing Java and I keep thinking to myself, every time I  
type SomeFoo someFoo = new SomeFoo(), and then again every time I type a  
semicolon, and every time I define a method with all the static typing  
in the signature, WHY??

Thanks again Matz. If people don’t get it, then it’s their loss 🙂

> **···**
>
> –  
> Dan North
> 
> > **[Thoughtworks: Delivering extraordinary impact together](https://www.thoughtworks.com/)**
> >
> > We are laser-focused on transforming your digital journey so you can make extraordinary impact today, tomorrow and beyond.

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [22 August 2003 18:57 UTC](https://rubytalk.org/t/integrated-webserver/7550/8 "2003-08-22T18:57:39Z")

</div>

Could it be trying to open an IPv6 socket? WEBrick is IPv6 aware…

> **···**
>
> Joel VanderWerf (vjoel@PATH.Berkeley.EDU) wrote:
> 
> > Looks nice. I tried this example (with minor modifications) and got
> > 
> > [2003-08-21 14:44:46] INFO WEBrick 1.3.1  
> > [2003-08-21 14:44:46] INFO ruby 1.8.0 (2003-08-04) [i686-linux]  
> > [2003-08-21 14:44:47] WARN TCPServer Error: Address family not  
> > supported by protocol - socket(2)
> > 
> > Could it be because I’m trying to run it inside a 192.\* network? (Tried  
> > googling for that error message, but that didn’t help much.)
> 
> –  
> Eric Hodel - [drbrain@segment7.net](mailto:drbrain@segment7.net) - [http://segment7.net](http://segment7.net)  
> All messages signed with fingerprint:  
> FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

---

<div class="post-metadata">

**Author:** ![GOTOU\_Yuuzou](https://avatars.discourse-cdn.com/v4/letter/g/a88e4f/32.png) [@GOTOU\_Yuuzou](https://rubytalk.org/u/GOTOU_Yuuzou)\
**Post date:** [22 August 2003 19:26 UTC](https://rubytalk.org/t/integrated-webserver/7550/9 "2003-08-22T19:26:56Z")

</div>

Hi,

In message [3F4541D9.8060403@path.berkeley.edu](mailto:3F4541D9.8060403@path.berkeley.edu),

> Looks nice. I tried this example (with minor modifications) and got
> 
> [2003-08-21 14:44:46] INFO WEBrick 1.3.1  
> [2003-08-21 14:44:46] INFO ruby 1.8.0 (2003-08-04) [i686-linux]  
> [2003-08-21 14:44:47] WARN TCPServer Error: Address family not  
> supported by protocol - socket(2)
> 
> Could it be because I’m trying to run it inside a 192.\* network? (Tried  
> googling for that error message, but that didn’t help much.)

If you want to run WEBrick only in IPv4 network,  
:BindAddress option may be useful.

s = HTTPServer.new(  
:Port =\> 2000,  
:DocumentRoot =\> Dir::pwd + “/htdocs”,  
:BindAddress =\> “0.0.0.0”  
)

I think the error may come from the incompatibility of  
getaddrinfo. What result does the following one-liner  
become?

% ruby -r socket -ve ‘p Socket::getaddrinfo(nil,2000,  
Socket::AF\_UNSPEC,Socket::SOCK\_STREAM,0,Socket::AI\_PASSIVE)’

> **···**
>
> `Joel VanderWerf [vjoel@PATH.Berkeley.EDU](mailto:vjoel@PATH.Berkeley.EDU)’ wrote:
> 
> –  
> gotoyuzo

---

<div class="post-metadata">

**Author:** ![Laurent\_Julliard4](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@Laurent\_Julliard4](https://rubytalk.org/u/Laurent_Julliard4)\
**Post date:** [22 August 2003 19:38 UTC](https://rubytalk.org/t/integrated-webserver/7550/10 "2003-08-22T19:38:33Z")

</div>

try to push \_why to add a section on it in his “what’s new” page 😉

> **···**
>
> il Fri, 22 Aug 2003 05:22:50 GMT, “Joe Cheng” [code@joecheng.com](mailto:code@joecheng.com) ha scritto::
> 
> > > did you noticed that webrick exists and is now part of the standard  
> > > distribution?
> > 
> > I didn’t know about webrick. That is SO FRICKIN’ COOL.

---

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Joel\_VanderWerf1](https://rubytalk.org/u/Joel_VanderWerf1)\
**Post date:** [23 August 2003 07:37 UTC](https://rubytalk.org/t/integrated-webserver/7550/11 "2003-08-23T07:37:28Z")

</div>

GOTOU Yuuzou wrote:

> Hi,
> 
> In message [3F4541D9.8060403@path.berkeley.edu](mailto:3F4541D9.8060403@path.berkeley.edu),
> 
> > Looks nice. I tried this example (with minor modifications) and got
> > 
> > [2003-08-21 14:44:46] INFO WEBrick 1.3.1  
> > [2003-08-21 14:44:46] INFO ruby 1.8.0 (2003-08-04) [i686-linux]  
> > [2003-08-21 14:44:47] WARN TCPServer Error: Address family not  
> > supported by protocol - socket(2)
> > 
> > Could it be because I’m trying to run it inside a 192.\* network? (Tried  
> > googling for that error message, but that didn’t help much.)
> 
> If you want to run WEBrick only in IPv4 network,  
> :BindAddress option may be useful.
> 
> s = HTTPServer.new(  
> :Port =\> 2000,  
> :DocumentRoot =\> Dir::pwd + “/htdocs”,  
> :BindAddress =\> “0.0.0.0”  
> )

Well, that’s some progress. Now the output is:

[2003-08-23 00:30:24] INFO WEBrick 1.3.1  
[2003-08-23 00:30:24] INFO ruby 1.8.0 (2003-08-04) [i686-linux]

But the process does not stay around (according to `ps -Af | grep ruby`), and my browser can’t connect to anything at the ports I tried  
(2000, 9000, 9123).

I also tried

:BindAddress =\> “192.168.1.3”

That’s the ip of my host.

> I think the error may come from the incompatibility of  
> getaddrinfo. What result does the following one-liner  
> become?
> 
> % ruby -r socket -ve ‘p Socket::getaddrinfo(nil,2000,  
> Socket::AF\_UNSPEC,Socket::SOCK\_STREAM,0,Socket::AI\_PASSIVE)’

$ ruby -r socket -ve ‘p  
Socket::getaddrinfo(nil,2000,Socket::AF\_UNSPEC,Socket::SOCK\_STREAM,0,Socket::AI\_PASSIVE)’  
ruby 1.8.0 (2003-08-04) [i686-linux]  
[[“AF\_INET6”, 2000, “::”, “::”, 10, 1, 6], [“AF\_INET”, 2000, “0.0.0.0”,  
“0.0.0.0”, 2, 1, 6]]

> **···**
>
> > `Joel VanderWerf [vjoel@PATH.Berkeley.EDU](mailto:vjoel@PATH.Berkeley.EDU)’ wrote:

---

<div class="post-metadata">

**Author:** ![GOTOU\_Yuuzou](https://avatars.discourse-cdn.com/v4/letter/g/a88e4f/32.png) [@GOTOU\_Yuuzou](https://rubytalk.org/u/GOTOU_Yuuzou)\
**Post date:** [23 August 2003 18:28 UTC](https://rubytalk.org/t/integrated-webserver/7550/12 "2003-08-23T18:28:03Z")

</div>

Hi,

In message [3F4719A3.4080903@path.berkeley.edu](mailto:3F4719A3.4080903@path.berkeley.edu),

> GOTOU Yuuzou wrote:
> 
> > If you want to run WEBrick only in IPv4 network,  
> > :BindAddress option may be useful.
> > 
> > s = HTTPServer.new(  
> > :Port =\> 2000,  
> > :DocumentRoot =\> Dir::pwd + “/htdocs”,  
> > :BindAddress =\> “0.0.0.0”  
> > )
> 
> Well, that’s some progress. Now the output is:
> 
> [2003-08-23 00:30:24] INFO WEBrick 1.3.1  
> [2003-08-23 00:30:24] INFO ruby 1.8.0 (2003-08-04) [i686-linux]
> 
> But the process does not stay around (according to `ps -Af | grep ruby`), and my browser can’t connect to anything at the ports I tried  
> (2000, 9000, 9123).

Hmm, it seems that your code didn’t call HTTPServer#start.  
Could you try the following code?

require ‘webrick’  
s = WEBrick::HTTPServer.new(  
:Port =\> 2000,  
:BindAddress =\> “0.0.0.0”,  
:DocumentRoot =\> Dir::pwd,  
:Logger =\> WEBrick::Log.new($stderr, WEBrick::Log::DEBUG)  
)  
trap(“INT”){ s.shutdown }  
s.start

> $ ruby -r socket -ve ‘p  
> Socket::getaddrinfo(nil,2000,Socket::AF\_UNSPEC,Socket::SOCK\_STREAM,0,Socket::AI\_PASSIVE)’  
> ruby 1.8.0 (2003-08-04) [i686-linux]  
> [[“AF\_INET6”, 2000, “::”, “::”, 10, 1, 6], [“AF\_INET”, 2000, “0.0.0.0”,  
> “0.0.0.0”, 2, 1, 6]]

it seems ok.

> **···**
>
> `Joel VanderWerf [vjoel@PATH.Berkeley.EDU](mailto:vjoel@PATH.Berkeley.EDU)’ wrote:
> 
> –  
> gotoyuzo

---

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Joel\_VanderWerf1](https://rubytalk.org/u/Joel_VanderWerf1)\
**Post date:** [23 August 2003 19:29 UTC](https://rubytalk.org/t/integrated-webserver/7550/13 "2003-08-23T19:29:23Z")

</div>

GOTOU Yuuzou wrote:

> Hmm, it seems that your code didn’t call HTTPServer#start.  
> Could you try the following code?

That’s it. Thanks!
