PyDocs

Nav

Internet Protocols and Support

BaseServer

socketserver

class (source) not WASI
  • BaseServer(server_address, RequestHandlerClass)
Base class for server classes.

Methods for the caller:

- __init__(server_address, RequestHandlerClass)
- serve_forever(poll_interval=0.5)
- shutdown()
- handle_request()  # if you do not use serve_forever()
- fileno() -> int   # for selector

Methods that may be overridden:

- server_bind()
- server_activate()
- get_request() -> request, client_address
- handle_timeout()
- verify_request(request, client_address)
- server_close()
- process_request(request, client_address)
- shutdown_request(request)
- close_request(request)
- service_actions()
- handle_error()

Methods for derived classes:

- finish_request(request, client_address)

Class variables that may be overridden by derived classes or
instances:

- timeout
- address_family
- socket_type
- allow_reuse_address
- allow_reuse_port

Instance variables:

- RequestHandlerClass
- socket
Changed in 3.6
  • 3.6: Support for the context manager protocol was added. Exiting the context manager is equivalent to calling server_close().
Members of BaseServer

a

address_family
The family of protocols to which the server’s socket belongs.
allow_reuse_address
Whether the server will allow the reuse of an address.

f

fileno
Return an integer file descriptor for the socket on which the server is listening.
finish_request
Finish one request by instantiating RequestHandlerClass.

g

get_request
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.

h

handle_error
Handle an error gracefully.
handle_request
Handle one request, possibly blocking.
handle_timeout
Called if no new request arrives within self.timeout.

p

process_request
Call finish_request.

r

request_queue_size
The size of the request queue.
RequestHandlerClass
The user-provided request handler class; an instance of this class is created for each request.

s

serve_forever
Handle one request at a time until shutdown.
server_activate
Called by constructor to activate the server.
server_address
The address on which the server is listening.
server_bind
Called by the server’s constructor to bind the socket to the desired address.
server_close
Called to clean-up the server.
service_actions
Called by the serve_forever() loop.
shutdown
Stops the serve_forever loop.
socket
The socket object on which the server will listen for incoming requests.
socket_type
The type of socket used by the server; socket.SOCK_STREAM and socket.SOCK_DGRAM are two common values.

t

timeout
Timeout duration, measured in seconds, or None if no timeout is desired.

v

verify_request
Verify the request.
0 Examples
No examples for socketserver/BaseServer.
See Also
No see-alsos for socketserver/BaseServer
0 Notes
No notes for BaseServer