Initial import to Tizen
[profile/ivi/python-twisted.git] / doc / words / examples / jabber_client.py
1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 # Originally written by Darryl Vandorp
5 # http://randomthoughts.vandorp.ca/
6
7 from twisted.words.protocols.jabber import client, jid
8 from twisted.words.xish import domish
9 from twisted.internet import reactor
10         
11 def authd(xmlstream):
12     print "authenticated"
13
14     presence = domish.Element(('jabber:client','presence'))
15     xmlstream.send(presence)
16     
17     xmlstream.addObserver('/message',  debug)
18     xmlstream.addObserver('/presence', debug)
19     xmlstream.addObserver('/iq',       debug)   
20
21 def debug(elem):
22     print elem.toXml().encode('utf-8')
23     print "="*20
24     
25 myJid = jid.JID('username@server.jabber/twisted_words')
26 factory = client.basicClientFactory(myJid, 'password')
27 factory.addBootstrap('//event/stream/authd',authd)
28 reactor.connectTCP('server.jabber',5222,factory)
29 reactor.run()