source:
ralphm-patches/pubsub_client_example.patch
Last change on this file was 56:fa1511cccfe2, checked in by Ralph Meijer <ralphm@…>, 11 years ago | |
---|---|
File size: 2.0 KB |
-
new file doc/examples/pubsub_client_create_node.tac
# HG changeset patch # Parent bbb746f7971831cb09e1539bfd3fefe862c3cc9e diff -r bbb746f79718 doc/examples/pubsub_client_create_node.tac
- + 1 """ 2 An XMPP Publish Subscribe publisher client as an XMPP client. 3 4 This client logs in as C{publisher@example.org}, creates a node at 5 C{pubsub.example.org} and prints the node identifier. 6 7 Note that some services may change the node identifier to adhere to local 8 policies. If you set L{NODE_IDENTIFIER} to C{None}, the service will create an 9 'instant node', with a unique node identifier. 10 """ 11 12 from twisted.application import service 13 from twisted.internet import reactor, task 14 from twisted.python import log 15 from twisted.words.protocols.jabber.jid import JID 16 from wokkel.client import XMPPClient 17 from wokkel.pubsub import PubSubClient 18 19 # Configuration parameters 20 21 THIS_JID = JID('publisher@example.org') 22 SERVICE_JID = JID('pubsub.example.org') 23 NODE_IDENTIFIER = 'test_node' 24 SECRET = 'secret' 25 LOG_TRAFFIC = True 26 27 class Publisher(PubSubClient): 28 29 count = None 30 loopingCall = None 31 nodeIdentifier = None 32 33 def connectionInitialized(self): 34 def cb(nodeIdentifier): 35 log.msg("The node %r was successfully created" % nodeIdentifier) 36 d = self.createNode(SERVICE_JID, NODE_IDENTIFIER) 37 d.addCallbacks(cb, log.err) 38 d.addCallback(lambda _: reactor.stop()) 39 40 41 def nodeCreated(self, nodeIdentifier): 42 self.nodeIdentifier = nodeIdentifier 43 self.count = 0 44 self.loopingCall = task.LoopingCall(self.doPublish) 45 self.loopingCall.start(5) 46 47 # Set up the Twisted application 48 49 application = service.Application("Publish Subscribe publisher") 50 51 client = XMPPClient(THIS_JID, SECRET) 52 client.logTraffic = LOG_TRAFFIC 53 client.setServiceParent(application) 54 55 pubsubHandler = PubSubClient() 56 pubsubHandler.setHandlerParent(client)
Note: See TracBrowser
for help on using the repository browser.