-
Return an integer file descriptor for the socket on which the server
is listening. This function is most commonly passed to
select.select(), to allow monitoring multiple servers in the
same process.
-
Process a single request. This function calls the following methods
in order: get_request(), verify_request(), and
process_request(). If the user-provided handle()
method of the handler class raises an exception, the server's
handle_error() method will be called.
-
Handle an infinite number of requests. This simply calls
handle_request() inside an infinite loop.
- address_family
-
The family of protocols to which the server's socket belongs.
socket.AF_INET and socket.AF_UNIX are two
possible values.
- RequestHandlerClass
-
The user-provided request handler class; an instance of this class is
created for each request.
- server_address
-
The address on which the server is listening. The format of addresses
varies depending on the protocol family; see the documentation for the
socket module for details. For Internet protocols, this is a tuple
containing a string giving the address, and an integer port number:
('127.0.0.1', 80)
, for example.
- socket
-
The socket object on which the server will listen for incoming requests.
The server classes support the following class variables:
- allow_reuse_address
-
Whether the server will allow the reuse of an address. This defaults
to False, and can be set in subclasses to change the policy.
- request_queue_size
-
The size of the request queue. If it takes a long time to process a
single request, any requests that arrive while the server is busy are
placed into a queue, up to request_queue_size requests. Once
the queue is full, further requests from clients will get a
``Connection denied'' error. The default value is usually 5, but this
can be overridden by subclasses.
- socket_type
-
The type of socket used by the server; socket.SOCK_STREAM
and socket.SOCK_DGRAM are two possible values.
There are various server methods that can be overridden by subclasses
of base server classes like TCPServer; these methods aren't
useful to external users of the server object.
-
Actually processes the request by instantiating
RequestHandlerClass and calling its handle() method.
-
Must accept a request from the socket, and return a 2-tuple containing
the new socket object to be used to communicate with the
client, and the client's address.
handle_error( |
request, client_address) |
-
This function is called if the RequestHandlerClass's
handle() method raises an exception. The default action is
to print the traceback to standard output and continue handling
further requests.
process_request( |
request, client_address) |
-
Calls finish_request() to create an instance of the
RequestHandlerClass. If desired, this function can create a
new process or thread to handle the request; the ForkingMixIn
and ThreadingMixIn classes do this.
-
Called by the server's constructor to activate the server. The default
behavior just listens to the server's socket.
May be overridden.
-
Called by the server's constructor to bind the socket to the desired
address. May be overridden.
verify_request( |
request, client_address) |
-
Must return a Boolean value; if the value is True, the request will be
processed, and if it's False, the request will be denied.
This function can be overridden to implement access controls for a server.
The default implementation always returns True.
Release 2.5a0, documentation updated on August 30, 2005.
See About this document... for information on suggesting changes.