Skip to content

Instantly share code, notes, and snippets.

@saghul
Created October 5, 2012 15:05
Show Gist options
  • Select an option

  • Save saghul/3840349 to your computer and use it in GitHub Desktop.

Select an option

Save saghul/3840349 to your computer and use it in GitHub Desktop.
Twisted Wokkel disco client example
from application import log
from functools import partial
from optparse import OptionParser
from twisted.internet import reactor
from twisted.words.protocols.jabber.jid import JID
from wokkel.client import DeferredClientFactory, clientCreator
from wokkel.disco import DiscoClientProtocol
def on_info(info):
reactor.stop()
def on_connection(options, stream):
global factory
log.msg('Connected')
protocol = DiscoClientProtocol()
protocol.setHandlerParent(factory.streamManager)
d = protocol.requestInfo(JID(options.target))
d.addCallback(on_info)
def main(options):
global factory
factory = DeferredClientFactory(JID(options.jid), options.password)
factory.streamManager.logTraffic = True
d = clientCreator(factory)
d.addCallback(partial(on_connection, options))
reactor.run()
if __name__ == '__main__':
parser = OptionParser()
parser.add_option('-j', '--jid', dest='jid')
parser.add_option('-p', '--password', dest='password')
parser.add_option('-t', '--target', dest='target')
options, args = parser.parse_args()
main(options)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment