Fantius
Fantius

Reputation: 3862

Ruby's GServer only wants to work on localhost

TCPServer.new(port) creates a server that can service requests from localhost or remote machines.

But GServer.new(port) creates a server that can only service requests from localhost.

In looking at GServer's source, it calls TCPServer.new(@host,@port). @host defaults to DEFAULT_HOST which is 127.0.0.1.

The source for TCPServer.new says:

# TCPServer.new([hostname,] port) => tcpserver
# Creates a new server socket bound to _port_.
# If _hostname_ is given, the socket is bound to it.

I would like to use GServer, but not bind to a certain host name. Is such a thing possible? Every example on the web uses only localhost.

It seems that if no host is specified to GServer, GServer should not specify a host to TCPServer.

Upvotes: 2

Views: 446

Answers (1)

cam
cam

Reputation: 14222

Use 0.0.0.0 for your hostname to bind to all interfaces.

Upvotes: 3

Related Questions