Base TCP server class. You must subclass GenericServer and provide a run method.

Attributes
Read

The server status. One of :Stop, :Running or :Shutdown

Read

The server configuration

Read

The server logger. This is independent from the HTTP access log.

Read

Tokens control the number of outstanding clients. The :MaxClients configuration sets this.

Read

Sockets listening for connections.

Class Methods

Creates a new generic server from config. The default configuration comes from default.

Instance Methods

Retrieves key from the configuration

Adds listeners from address and port to the server. See WEBrick::Utils::create_listeners for details.

You must subclass GenericServer and implement #run which accepts a TCP client socket

Shuts down the server and all listening sockets. New listeners must be provided to restart the server.

ServerNameIndication callback

Starts the server and runs the block for each connection. This method does not return until the server is stopped from a signal handler or another thread using stop or shutdown.

If the block raises a subclass of StandardError the exception is logged and ignored. If an IOError or Errno::EBADF exception is raised the exception is ignored. If an Exception subclass is raised the exception is logged and re-raised which stops the server.

To completely shut down a server call shutdown from ensure:

server = WEBrick::GenericServer.new
# or WEBrick::HTTPServer.new

begin
  server.start
ensure
  server.shutdown
end

Stops the server from accepting new connections.