Exemplo n.º 1
0
rootdir = os.path.realpath(
    os.path.join(os.path.dirname(sys.argv[0]), '..', '..'))
sys.path.insert(0, rootdir)
os.chdir(rootdir)

from examples.pubsub import base

from txzmq import ZmqEndpoint, ZmqFactory, ZmqPubConnection

(options, args) = base.getOptionsAndArgs()


def publish(server):
    data = str(time.time())
    print "Publishing %r ..." % data
    server.publish(data)
    print "Done."
    reactor.callLater(1, publish, server)


def onConnect(server):
    print "Connected!"
    publish(server)


endpoint = ZmqEndpoint(options.method, options.endpoint)
server = ZmqPubConnection(endpoint)
deferred = server.listen(ZmqFactory())
deferred.addCallback(onConnect)
reactor.run()
Exemplo n.º 2
0
from examples.pubsub import base

from txzmq import ZmqEndpoint, ZmqFactory, ZmqPubConnection, ZmqSubConnection

(options, args) = base.getOptionsAndArgs()


def publish(server):
    data = str(time.time())
    print "publishing %r" % data
    server.publish(data)
    reactor.callLater(1, publish, server)


class MySubscriber(ZmqSubConnection):
    def gotMessage(self, message, tag):
        print "message received: %s (%s)" % (message, tag)


endpoint = ZmqEndpoint(options.method, options.endpoint)
if options.mode == "publisher":
    server = ZmqPubConnection(endpoint)
    server.listen(ZmqFactory())
    publish(server)
elif options.mode == "subscriber":
    client = MySubscriber(endpoint)
    client.connect(ZmqFactory())
    client.subscribe("")
reactor.run()
Exemplo n.º 3
0
from txzmq import ZmqEndpoint, ZmqFactory, ZmqPubConnection, ZmqSubConnection


(options, args) = base.getOptionsAndArgs()


def publish(server):
    data = str(time.time())
    print "publishing %r" % data
    server.publish(data)
    reactor.callLater(1, publish, server)


class MySubscriber(ZmqSubConnection):

    def gotMessage(self, message, tag):
        print "message received: %s (%s)" % (message, tag)


endpoint = ZmqEndpoint(options.method, options.endpoint)
if options.mode == "publisher":
    server = ZmqPubConnection(endpoint)
    server.listen(ZmqFactory())
    publish(server)
elif options.mode == "subscriber":
    client = MySubscriber(endpoint)
    client.connect(ZmqFactory())
    client.subscribe("")
reactor.run()
Exemplo n.º 4
0
    os.path.dirname(sys.argv[0]), '..', '..'))
sys.path.insert(0, rootdir)
os.chdir(rootdir)

from examples.pubsub import base

from txzmq import ZmqEndpoint, ZmqFactory, ZmqPubConnection


(options, args) = base.getOptionsAndArgs()


def publish(server):
    data = str(time.time())
    print "Publishing %r ..." % data
    server.publish(data)
    print "Done."
    reactor.callLater(1, publish, server)


def onConnect(server):
    print "Connected!"
    publish(server)


endpoint = ZmqEndpoint(options.method, options.endpoint)
server = ZmqPubConnection(endpoint)
deferred = server.listen(ZmqFactory())
deferred.addCallback(onConnect)
reactor.run()