tanszek:oktatas:iss_t:xml-rpc
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
tanszek:oktatas:iss_t:xml-rpc [2023/03/19 14:31] – létrehozva knehez | tanszek:oktatas:iss_t:xml-rpc [2024/01/12 10:30] (current) – knehez | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== XML-RPC ===== | + | ===== XML-RPC |
- | XML-RPC is a popular integration method used in web development, | + | [[https:// |
+ | ===== Server ===== | ||
- | 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 | + | <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 | ||
+ | def adder_function(x, | ||
+ | return x + y | ||
+ | server.register_function(adder_function, | ||
+ | |||
+ | # Register an instance; all the methods | ||
+ | # published as XML-RPC methods (in this case, just ' | ||
+ | class MyFuncs: | ||
+ | def mul(self, x, y): | ||
+ | return x * y | ||
+ | |||
+ | | ||
+ | |||
+ | # Run the server' | ||
+ | server.serve_forever() | ||
+ | </ | ||
+ | |||
+ | ===== Client ===== | ||
+ | |||
+ | <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()) | ||
+ | </ |
tanszek/oktatas/iss_t/xml-rpc.1679236316.txt.gz · Last modified: 2023/03/19 14:31 by knehez