Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > WEBrick doesn't work (permission/port error)

Reply
Thread Tools

WEBrick doesn't work (permission/port error)

 
 
P. A.
Guest
Posts: n/a
 
      12-07-2009
Hi.

I get an error when I start a WEBrick server.

Here's my application.

# server.rb
# encoding: utf-8

require 'webrick'

class Server
class << self
def start(config = {})
config.merge(:BindAddress => '0.0.0.0', ort => 4321)
server = WEBrick::HTTPServer.new(config)
trap('INT') { server.shutdown }
end
end
end

Server.start

$ ruby1.9.2dev server.rb
[2009-12-08 00:21:53] INFO WEBrick 1.3.1
[2009-12-08 00:21:53] INFO ruby 1.9.2 (2009-11-14) [i686-linux]
[2009-12-08 00:21:58] WARN TCPServer Error: Permission denied - bind(2)
[2009-12-08 00:21:58] WARN TCPServer Error: Permission denied - bind(2)
/opt/ruby-1.9.2-dev/lib/ruby/1.9.1/webrick/utils.rb:73:in `initialize':
Permission denied - bind(2) (Errno::EACCES)
from /opt/ruby-1.9.2-dev/lib/ruby/1.9.1/webrick/utils.rb:73:in
`new'
from /opt/ruby-1.9.2-dev/lib/ruby/1.9.1/webrick/utils.rb:73:in
`block in create_listeners'
from /opt/ruby-1.9.2-dev/lib/ruby/1.9.1/webrick/utils.rb:70:in
`each'
from /opt/ruby-1.9.2-dev/lib/ruby/1.9.1/webrick/utils.rb:70:in
`create_listeners'
from /opt/ruby-1.9.2-dev/lib/ruby/1.9.1/webrick/server.rb:74:in
`listen'
from /opt/ruby-1.9.2-dev/lib/ruby/1.9.1/webrick/server.rb:62:in
`initialize'
from
/opt/ruby-1.9.2-dev/lib/ruby/1.9.1/webrick/httpserver.rb:24:in
`initialize'
from server.rb:24:in `new'
from server.rb:24:in `start'
from server.rb:31:in `<main>'

When I start it as a root I get another error.

# ruby1.9.2dev server.rb
[2009-12-08 00:26:18] INFO WEBrick 1.3.1
[2009-12-08 00:26:18] INFO ruby 1.9.2 (2009-11-14) [i686-linux]
[2009-12-08 00:26:23] WARN TCPServer Error: Address already in use -
bind(2)

I also get these errors while I use a stable version of Ruby (1.9.1). I
haven't got any other applications working on port 4321.

Debian GNU/Linux 5.0.3;
Ruby 1.9.1, 1.9.2dev;
WEBrick 1.3.1.

What is the reason of this bug?

Thanks.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Luis Lavena
Guest
Posts: n/a
 
      12-08-2009
On Dec 7, 6:34*pm, "P. A." <shama...@hotmail.com> wrote:
> Hi.
>
> I get an error when I start a WEBrick server.
>
> Here's my application.
>
> # server.rb
> # encoding: utf-8
>
> require 'webrick'
>
> class Server
> * class << self
> * * def start(config = {})
> * * * config.merge(:BindAddress => '0.0.0.0', ort => 4321)
> * * * server = WEBrick::HTTPServer.new(config)
> * * * trap('INT') { server.shutdown }
> * * end
> * end
> end
>
> Server.start
>
> $ ruby1.9.2dev server.rb
> [2009-12-08 00:21:53] INFO *WEBrick 1.3.1
> [2009-12-08 00:21:53] INFO *ruby 1.9.2 (2009-11-14) [i686-linux]
> [2009-12-08 00:21:58] WARN *TCPServer Error: Permission denied - bind(2)
> [2009-12-08 00:21:58] WARN *TCPServer Error: Permission denied - bind(2)
> /opt/ruby-1.9.2-dev/lib/ruby/1.9.1/webrick/utils.rb:73:in `initialize':
> Permission denied - bind(2) (Errno::EACCES)
> * * * * from /opt/ruby-1.9.2-dev/lib/ruby/1.9.1/webrick/utils.rb:73:in
> `new'
> * * * * from /opt/ruby-1.9.2-dev/lib/ruby/1.9.1/webrick/utils.rb:73:in
> `block in create_listeners'
> * * * * from /opt/ruby-1.9.2-dev/lib/ruby/1.9.1/webrick/utils.rb:70:in
> `each'
> * * * * from /opt/ruby-1.9.2-dev/lib/ruby/1.9.1/webrick/utils.rb:70:in
> `create_listeners'
> * * * * from /opt/ruby-1.9.2-dev/lib/ruby/1.9.1/webrick/server.rb:74:in
> `listen'
> * * * * from /opt/ruby-1.9.2-dev/lib/ruby/1.9.1/webrick/server.rb:62:in
> `initialize'
> * * * * from
> /opt/ruby-1.9.2-dev/lib/ruby/1.9.1/webrick/httpserver.rb:24:in
> `initialize'
> * * * * from server.rb:24:in `new'
> * * * * from server.rb:24:in `start'
> * * * * from server.rb:31:in `<main>'
>
> When I start it as a root I get another error.
>
> # ruby1.9.2dev server.rb
> [2009-12-08 00:26:18] INFO *WEBrick 1.3.1
> [2009-12-08 00:26:18] INFO *ruby 1.9.2 (2009-11-14) [i686-linux]
> [2009-12-08 00:26:23] WARN *TCPServer Error: Address already in use -
> bind(2)
>
> I also get these errors while I use a stable version of Ruby (1.9.1). I
> haven't got any other applications working on port 4321.
>
> Debian GNU/Linux 5.0.3;
> Ruby 1.9.1, 1.9.2dev;
> WEBrick 1.3.1.
>
> What is the reason of this bug?
>


Is not a bug, it clearly indicates that another process/server is
already bound to that port.

Please verify that your script wasn't running in the background or you
using a port that is already in use by other program/service.

--
Luis Lavena
 
Reply With Quote
 
 
 
 
P. A.
Guest
Posts: n/a
 
      12-08-2009
I solved it by myself.

The problem was that I stated a WEBrick server without initial
configuration because I used the Hash#merge method instead Hash#merge!
(mutator).

So, the code should be changed to work properly.

# IT DOESN'T WORKS!
# encoding: utf-8

require 'webrick'

class Server
class << self
def start(config = {})
config.merge(:BindAddress => '0.0.0.0', ort => 4321) # the error
source
puts config # returns {} on start
server = WEBrick::HTTPServer.new(config)
trap('INT') { server.shutdown }
server.start
end
end
end

# WORKS!
# encoding: utf-8

require 'webrick'

class Server
class << self
def start(config = {})
config.merge!(:BindAddress => '0.0.0.0', ort => 4321) # changes
the config hash
puts config # returns {:BindAddress => '0.0.0.0', ort => 4321}
on start
server = WEBrick::HTTPServer.new(config)
trap('INT') { server.shutdown }
server.start
end
end
end

Cheers!
--
Posted via http://www.ruby-forum.com/.

 
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
queuing work in a web app (sinatra/webrick) Gurpal 2000 Ruby 9 11-19-2009 01:45 AM
How to make SSl work with webrick Bishal Acharya Ruby 1 11-26-2008 11:47 AM
How to get DRb and Webrick to work together? Sal Syed Ruby 1 09-01-2007 08:48 AM
WEBrick::Daemon and WEBrick Aaron Smith Ruby 2 03-18-2007 03:47 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57