The main script
Now that we have the subroutines and callbacks set up, all we need to do is define the Jabber server and room information:
Server = 'gnu.mine.nu' Username = 'kassist' Password = 'pass' Resource = 'py' Room = 'jdev' ConfServ = 'conference.jabber.org' Nick = 'kassist'
The kassist user can be set up simply by using the
reguser script presented in
Section 7.4:
$ ./reguser gnu.mine.nu username=kassist password=pass
[Attempt] (kassist) Successful registration
$In the same way as in previous recipes’ scripts, a connection attempt is made, followed by an authentication attempt:
con = jabber.Client(host=Server,debug=0,log=0)
try:
con.connect()
except IOError, e:
print "Couldn't connect: %s" % e
sys.exit(0)
else:
print "Connected"
if con.auth(Username,Password,Resource):
print "Logged in as %s to server %s" % ( Username, Server )
else:
print "Problems authenticating: ", con.lastErr, con.lastErrCode
sys.exit(1)
Then the message and presence callbacks messageCB()
and presenceCB() are defined to the
connection object in con:
con.setMessageHandler(messageCB) con.setPresenceHandler(presenceCB)
After sending initial presence, informing the JSM (and anyone who
might be subscribed to kassist’s presence) of the
assistant’s availability:
con.send(jabber.Presence())
we also construct—from the
Room, ConfServ, and
Nick variables—and send
the <presence/> element for negotiating
entry to the jdev room hosted by the Conferencing
component at conference.jabber.org:
roomjid = Room + '@' + ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access