tanszek:oktatas:iss_t:xml-rpc
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tanszek:oktatas:iss_t:xml-rpc [2023/03/19 14:34] – knehez | tanszek:oktatas:iss_t:xml-rpc [2026/03/16 09:32] (current) – [Server] knehez | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== XML-RPC ===== | + | ===== XML-RPC |
| + | |||
| + | [[https:// | ||
| + | ===== Server in Python ===== | ||
| + | |||
| + | <sxh python> | ||
| + | from xmlrpc.server import SimpleXMLRPCServer | ||
| + | from xmlrpc.server import SimpleXMLRPCRequestHandler | ||
| + | |||
| + | # Restrict to a particular path. | ||
| + | class RequestHandler(SimpleXMLRPCRequestHandler): | ||
| + | rpc_paths = ('/ | ||
| + | |||
| + | # Create server | ||
| + | with SimpleXMLRPCServer((' | ||
| + | requestHandler=RequestHandler) as server: | ||
| + | server.register_introspection_functions() | ||
| + | |||
| + | # Register pow() function; this will use the value of | ||
| + | # pow.__name__ as the name, which is just ' | ||
| + | server.register_function(pow) | ||
| + | |||
| + | # Register a function under a different name | ||
| + | def adder_function(x, | ||
| + | return x + y | ||
| + | server.register_function(adder_function, | ||
| + | |||
| + | # Register an instance; all the methods of the instance are | ||
| + | # published as XML-RPC methods (in this case, just ' | ||
| + | class MyFuncs: | ||
| + | def mul(self, x, y): | ||
| + | return x * y | ||
| + | |||
| + | server.register_instance(MyFuncs()) | ||
| + | |||
| + | # Run the server' | ||
| + | server.serve_forever() | ||
| + | </ | ||
| + | |||
| + | ===== Client - in Python===== | ||
| + | |||
| + | <sxh python> | ||
| + | import xmlrpc.client | ||
| + | |||
| + | s = xmlrpc.client.ServerProxy(' | ||
| + | print(s.pow(2, | ||
| + | print(s.add(2, | ||
| + | print(s.mul(5, | ||
| + | |||
| + | # Print list of available methods | ||
| + | print(s.system.listMethods()) | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== Task: XML-RPC – Remote Task Manager ==== | ||
| + | |||
| + | The goal of this exercise is to understand how **Remote Procedure Calls (RPC)** work in a client–server architecture using the XML-RPC protocol. Implement a simple **task management system** consisting of a Python **XML-RPC server** and a Python **client application**. | ||
| + | |||
| + | ==== Server ==== | ||
| + | |||
| + | Create an XML-RPC server in Python that manages a list of tasks. Each task should contain the following fields: | ||
| + | |||
| + | * **id** – unique integer identifier | ||
| + | * **title** – short text describing the task | ||
| + | * **completed** – boolean value indicating whether the task is finished | ||
| + | |||
| + | The server must provide the following remote methods: | ||
| + | |||
| + | ^ Method ^ Description ^ | ||
| + | | add_task(title) | Creates a new task and returns the generated task ID | | ||
| + | | list_tasks() | Returns all tasks as a list of dictionaries | | ||
| + | | complete_task(task_id) | Marks the specified task as completed | | ||
| + | | delete_task(task_id) | Removes the specified task | | ||
| + | | get_task(task_id) | Returns the details of a single task | | ||
| + | | get_task_by_title(title) | Returns the details of a single task (by title string) | | ||
| + | |||
| + | The server should store tasks **in memory** while it is running. | ||
| + | |||
| + | ==== Client ==== | ||
| + | |||
| + | Write a Python client that connects to the XML-RPC server and allows the user to interact with the task manager. The client program should: | ||
| + | |||
| + | * connect to the XML-RPC server | ||
| + | * call the remote methods | ||
| + | * display results in a readable format | ||
| + | |||
| + | The client should provide a simple **command line menu**, for example: | ||
| + | |||
| + | <code python> | ||
| + | 1 - Add task | ||
| + | 2 - List tasks | ||
| + | 3 - Complete task | ||
| + | 4 - Delete task | ||
| + | 5 - Show task details by id | ||
| + | 6 - Show task details by title | ||
| + | 0 - Exit | ||
| + | </ | ||
| - | XML-RPC is a popular integration method used in web development, | ||
| - | XML-RPC is a widely adopted integration method because it is platform-independent and can be used with any programming language that supports HTTP and XML. It is also a lightweight protocol that uses a small amount of bandwidth and can be easily implemented on both the client and server sides. | ||
| - | [[https:// | ||
tanszek/oktatas/iss_t/xml-rpc.1679236480.txt.gz · Last modified: 2023/03/19 14:34 by knehez
