January 2002
Beginner
480 pages
13h 15m
English
Now that we’ve got our Jabber-RPC responder all set up, it’s time
to turn our attention to our requester, JabberRPCRequester, shown in Example 10-12.
This is a Python script that uses the Jabberpy library
and Pythonware’s xmlrpclib library.
It’s a pretty simple affair.
import jabber
import xmlrpclib
import string
import sys
Server = 'qmacro.dyndns.org'
Username = 'client'
Password = 'pass'
Resource = 'jrpc-client'
Endpoint = 'server@gnu.mine.nu/jrpc-server';
Method = 'examples.getCountyName';
county = string.atoi(sys.argv[1])
con = jabber.Client(host=Server)
try:
con.connect()
except IOError, e:
print "Couldn't connect: %s" % e
sys.exit(0)
con.auth(Username,Password,Resource)
request = xmlrpclib.dumps(((county),),
methodname=Method);
iq = jabber.Iq(to=Endpoint, type="set')
iq.setQuery('jabber:iq:rpc')
iq.setQueryPayload(request)
result = con.SendAndWaitForResponse(iq)
if result.getType() == 'result':
response = str(result.getQueryPayload())
parms, func = xmlrpclib.loads(response)
print parms[0]
else:
print "Could not complete call"
con.disconnect()Read now
Unlock full access