Pieter,

On Thu, Sep 9, 2010 at 1:33 AM, Pieter Hintjens <[email protected]> wrote:
> Hunter,
>
> Thanks, the two examples are now added to the repository and should show up.

What repo did you add these examples to?  Would it make sense to have
them in the pyzmq examples?

Cheers,

Brian

> -Pieter
>
> On Wed, Sep 8, 2010 at 9:53 PM, Hunter Ford <[email protected]> wrote:
>> Python Code Example: Synchronized Pub Sub
>>
>> syncpub.py
>>
>> #
>> #  Synchronized publisher
>> #
>> import zmq
>>
>> #  We wait for 10 subscribers
>> SUBSCRIBERS_EXPECTED = 2
>>
>> def main():
>>    context = zmq.Context()
>>
>>    # Socket to talk to clients
>>    publisher = context.socket(zmq.PUB)
>>    publisher.bind('tcp://*:5561')
>>
>>    # Socket to receive signals
>>    syncservice = context.socket(zmq.REP)
>>    syncservice.bind('tcp://*:5562')
>>
>>    # Get synchronization from subscribers
>>    subscribers = 0
>>    while subscribers < SUBSCRIBERS_EXPECTED:
>>        # wait for synchronization request
>>        msg = syncservice.recv()
>>        # send synchronization reply
>>        syncservice.send('')
>>        subscribers += 1
>>        print "+1 subscriber"
>>
>>    # Now broadcast exactly 1M updates followed by END
>>    for i in range(1000000):
>>       publisher.send('Rhubarb');
>>
>>    publisher.send('END')
>>
>> if __name__ == '__main__':
>>    main()
>>
>> syncsub.py
>>
>> #
>> #  Synchronized subscriber
>> #
>> import zmq
>>
>> def main():
>>    context = zmq.Context()
>>
>>    # First, connect our subscriber socket
>>    subscriber = context.socket(zmq.SUB)
>>    subscriber.connect('tcp://localhost:5561')
>>    subscriber.setsockopt(zmq.SUBSCRIBE, "")
>>
>>    # Second, synchronize with publisher
>>    syncclient = context.socket(zmq.REQ)
>>    syncclient.connect('tcp://localhost:5562')
>>
>>    # send a synchronization request
>>    syncclient.send('')
>>
>>    # wait for synchronization reply
>>    syncclient.recv()
>>
>>    # Third, get our updates and report how many we got
>>    nbr = 0
>>    while True:
>>        msg = subscriber.recv()
>>        if msg == 'END':
>>            break
>>        nbr += 1
>>
>>    print 'Received %d updates' % nbr
>>
>> if __name__ == '__main__':
>>    main()
>>
>>
>>
>> _______________________________________________
>> zeromq-dev mailing list
>> [email protected]
>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
>>
>
>
>
> --
> -
> Pieter Hintjens
> iMatix - www.imatix.com
> _______________________________________________
> zeromq-dev mailing list
> [email protected]
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>



-- 
Brian E. Granger, Ph.D.
Assistant Professor of Physics
Cal Poly State University, San Luis Obispo
[email protected]
[email protected]
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to