BaseRequestHandler class that does everything except process the incoming data
TCPServer creates a new handler each time it gets a connection and calls that object's handle method
simple_server.py reads up to 1024 bytes of data and returns a message
"""Basic socket server."""importsocketserverCHUNK_SIZE=1024SERVER_ADDRESS=("localhost",5000)classMyHandler(socketserver.BaseRequestHandler):defhandle(self):data=self.request.recv(CHUNK_SIZE)cli=self.client_address[0]msg=f"server received {len(data)} bytes from {cli}"print(msg)print(data)self.request.sendall(bytes(msg,"utf-8"))if__name__=="__main__":server=socketserver.TCPServer(SERVER_ADDRESS,MyHandler)server.serve_forever()