Created
June 29, 2011 14:39
-
-
Save matburt/1053960 to your computer and use it in GitHub Desktop.
Create/Subscribe an xmpp node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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