Skip to content

Instantly share code, notes, and snippets.

@matburt
Created June 29, 2011 14:39
Show Gist options
  • Save matburt/1053960 to your computer and use it in GitHub Desktop.
Save matburt/1053960 to your computer and use it in GitHub Desktop.
Create/Subscribe an xmpp node
import sys
from twisted.internet import reactor
from twisted.python import log
from twisted.words.protocols.jabber.jid import JID
from wokkel import client, pubsub
jid_publisher = JID("user@host")
secret = "test123"
service = JID('pubsub.host')
nodeIdentifier = "/testNode"
log.startLogging(sys.stdout, setStdout=0)
factory = client.DeferredClientFactory(jid_publisher, secret)
factory.streamManager.logTraffic = True
ps = pubsub.PubSubClient()
ps.setHandlerParent(factory.streamManager)
# d = client.clientCreator(factory)
reactor.connectTCP('host', 5222, factory)
d = factory.deferred
d.addCallback(lambda _: ps.createNode(service, nodeIdentifier))
d.addCallback(lambda _: factory.streamManager.xmlstream.sendFooter())
d.addErrback(log.err)
d.addBoth(lambda _: reactor.callLater(1, reactor.stop))
reactor.run()
import sys
from twisted.internet import reactor
from twisted.python import log
from twisted.words.protocols.jabber.jid import JID
from wokkel import client, pubsub
jid_publisher = JID("user@host")
secret = "test123"
service = JID('user@host')
nodeIdentifier = "/testNode"
jid_subscriber = JID("user@host")
log.startLogging(sys.stdout, setStdout=0)
factory = client.DeferredClientFactory(jid_publisher, secret)
factory.streamManager.logTraffic = True
ps = pubsub.PubSubClient()
ps.setHandlerParent(factory.streamManager)
# d = client.clientCreator(factory)
reactor.connectTCP('host', 5222, factory)
d = factory.deferred
d.addCallback(lambda _: ps.subscribe(service, nodeIdentifier, jid_subscriber))
d.addCallback(lambda _: factory.streamManager.xmlstream.sendFooter())
d.addErrback(log.err)
d.addBoth(lambda _: reactor.callLater(1, reactor.stop))
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment