This is a set of Python classes that implement XML-RPC using the Jabber protocol as transport. It supports both secure (SSL) and insecure connections.
Elegant and easy to use interfaces for both XML-RPC server and client are available. Both server and client are clients of Jabber protocol and need regular Jabber accounts on any Jabber server - public or private.
Use the EasyJabberXMLRPCServer
class. Its constructor takes the following arguments: JabberServer = "chrome.pl", JabberUsername = "_serv", JabberPassword = "test", JabberResource="rpcServer", JabberPort = 5223, JabberConnection = "SSL", ConnectionTimeout = 5
To register a method to be exported by the server, use the register_function()
method. It takes the following arguments: function, name = None
In order for the server to start listening, you need to call the serve_forever()
method. It takes no arguments.
In short, the whole server setup takes as much as four lines of code:
import EasyJabberXMLRPCServer def test(number): return "dupa" + str(number) serv = EasyJabberXMLRPCServer() serv.register_function(test) print serv serv.serve_forever()
Using the client is not too complicated either. Use the class EasyJabberXMLRPCClient
. Its constructor takes the following arguments: JabberServer, JabberUsername, JabberPassword, RpcServerJid, JabberResource="rpcClient", JabberPort = 5223, JabberConnection = "SSL", ConnectionTimeout=20
ServersJabberUsername@ServersJabberServer/ServersJabberResource
After you call the constructor, the class connects to Jabber server and then to XMLRPC server and, if you get no exception, everything was successful and you can call the methods exported by server as if they were client's methods (for example print ClientInstance.test(param1, param2)
)
So, in three lines of code we have a working client:
import EasyJabberXMLRPCClient cli = EasyJabberXMLRPCClient(JabberServer="chrome.pl", JabberUsername = "_client", JabberPassword = "test", RpcServerJid = "_serv@chrome.pl/rpcServer") print cli.test(0x29a) # Here the "test" method exported by server is called # alternatively, you can call methods this way: print cli.Call("test", (0x29a,))
2006 GDR! - http://gdr.geekhood.net/
Sponsored by Cybertronica
Uses JabberXMLRPCClient.py by gian paolo ciceri <gp.ciceri@acm.org>
Licence: GPL