Yet another HTTP/1.1 server.
This class is the core of a light weight Web Server. This server
is started as a Thread listening on the supplied port, and
dispatches to an implementation of
a Handler to service http requests. If no handler is
supplied, then the FileHandler is used.
A ChainHandler is provided to allow multiple handlers in one server.
Limitations:
Starts a new thread for each connection. This may be expensive.
The hostname that this Server should use to identify itself in
an HTTP Redirect. If null, the hostname is derived
by calling InetAddress.getHostAddress.
InetAddress.getHostName would generally be the wrong
thing to return because it returns only the base machine name
xxx and not the machine name as it needs to appear
to the rest of the network, such as xxx.yyy.com.
The handler is passed a prefix to identify which items in the
properties object are relevent. By convention, non-empty strings
end with ".", allowing nested prefixes to be easily distinguished.
timeout
public int timeout
Time in milliseconds before this Server closes an idle socket or
in-progress request.
The default value is 30000.
maxRequests
public int maxRequests
Maximum number of consecutive requests allowed on a single
kept-alive socket.
The default value is 25.
maxThreads
public int maxThreads
The max number of threads allowed for the entire VM
bufsize
public int bufsize
Default buffer size for copies to and from client sockets.
Create a server using the provided listener socket.
This server will call the Handler.respond method
of the specified handler. The specified handler should either
respond to the request or perform further dispatches to other
handlers.
Parameters:
listen - The socket this server should listen to.
For ordinary sockets, this is simply:
new ServerSocket(port), where port
is the network port to listen on. Alternate implementations
of ServerSocket, such as ssl versions
may be used instead.
handlerName - The name of the handler used to process http requests.
It must implement the Handler interface.
props - Arbitrary information made available to the handler.
May be null.
Set up the server. this allows a server to be created with
newInstance() followed by setup(), instead of using the
above initializer, making it easier to start sub-classes
of the server.
Loops, accepting socket connections and replying to HTTP requests.
This is called indirectly via Thread.start().
Many things in the server are not initialized until this point,
because the user may have set some related configuration options
between the time this server was allocated and the time it was
started. For instance, the main Handler is not
initialized until now, because its Handler.init method
may have wanted to examine server member variables such as
hostName or bufsize.