socketserver.TCPServer()
socketserver.TCPServer() is a Python function in the SocketServer Module category. Creates a TCP server that handles connections. The syntax is socketserver.TCPServer(server_address, RequestHandlerClass, bind_and_activate=True). Returns: TCPServer object. A typical example: from socketserver import TCPServer, BaseRequestHandler
class Handler(BaseRequestHandler):
def handle(self):
self.request.sendall(b"Hello!")
server = TCPServer(("", 9999), Handler)
server.serve_forever(). A close sibling is socketserver.UDPServer(), which creates a UDP server for connectionless datagrams. A close sibling is socketserver.ThreadingTCPServer(), which creates a TCP server that handles each connection in a new thread. A close sibling is socketserver.ForkingTCPServer(), which creates a TCP server that forks a process for each connection (Unix). More about this category: Server frameworks — TCPServer, UDPServer, ThreadingTCPServer, ForkingTCPServer. Related SocketServer Module entries: socketserver.UDPServer(), socketserver.ThreadingTCPServer(), socketserver.ForkingTCPServer(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details. You can try socketserver.TCPServer() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.