[Twisted-Python] Writing a Jabber client
E.A.M.Huijbers at student.tue.nl
Mon May 24 11:10:09 EDT 2004
I'm having trouble writing a Jabber client with Twisted. I came across a
simple sample, and tried to build out from it, but for some reason
it's barely working.
When I run the application in the attached script, the logon goes fine,
and I can receive messages sent to the account, but it never seems to
receive subscription requests. When I ran it on an account that already
had some items on the contact list, I did receive <presence> messages to
indcate that a user changed status, but I don't receive <presence
Ultimately, I tacked a "/*" handler on to the code to see if I was
receiving any packets at all, but the only thing that seems to trigger
anything are messages.
This is very frustrating for me. Is it a problem with the code, or am I
missing something in the Jabber protocol?
Any help would be greatly appreciated.
P.S: Please don't mind the code, I know it's a bit (a lot) hackish right
now, but my first step is to get it running. I'll make it beautiful
afterwards ;) .
##### code starts here #####
from twisted.protocols.jabber import client, jid
from twisted.protocols import xmlstream
from twisted.xish import domish
from twisted.internet import reactor
name = 'Foo'
resource = 'PythonBot'
password = 'foobar'
me = '%s@%s/%s' % (name, server, resource)
thexmlstream = None
tryandregister = 1
thexmlstream = xmlstream
print "we've authd!"
#need to send presence so clients know we're
presence = domish.Element(('jabber:client', 'presence'))
print 'Got message: %s' % str(el.attributes)
print 'Got something: %s -> %s' % (el.name, str(el.attributes))
print 'Got IQ: %s' % str(el.attributes)
print 'We got a presence message!'
t = el.attributes['type']
if t == 'subscribe':
# Grant every subscription request
# Big fat ignore
print 'Invalid user!'
tryandregister = 0
print 'Attempting to register...'
print 'Auth failed!'
print 'Register failed!'
myJid = jid.JID(me)
secret = password
factory = client.basicClientFactory(myJid,secret)
# Register authentication callbacks
reactor.connectTCP(server, 5222, factory)
More information about the Twisted-Python