[zeromq-dev] Bind, publish, unbind, repeat

Marcus Ottosson konstruktion at gmail.com
Fri Jun 20 12:13:27 CEST 2014

Hi all, first time on this mailing-list, let me know if anything is amiss.

I originally posted on Stackoverflow
but had previously seen mentions of otherwise posting on an active
mailing-list so here goes.

Why isn’t this working?


import zmqimport time
if __name__ == '__main__':
    context = zmq.Context()

    socket = context.socket(zmq.PUB)

    while True:
        print "I: Publishing"

        socket.send_multipart(['general', 'Unique peer information'])



import zmq
if __name__ == '__main__':
    context = zmq.Context()

    socket = context.socket(zmq.SUB)
    socket.setsockopt(zmq.SUBSCRIBE, 'general')

    print "I: Scanning 5555"

    while True:
        message = socket.recv_multipart()
        print "I: Receiving: {}".format(message)

I’m attempting to broadcast multiple peers over the same port, on the same
computer and have a single “scanner” listen in and “see” who is available.
Each peer would broadcast its contact information, a client would then use
the scanner to find out who is available and then use the broadcasted
information to connect via a REQ/REP channel.

To make this work, I’ve attempted to quickly bind a PUB socket, broadcast
information about a peer, and then unbind so as to let other peers bind to
the same socket, at a different time, and broadcast a different set of
identifiers for the next peer.

I’m suspecting that messages get discarded before getting sent due to the
unbinding (the same occurs with a call to close()) but I can’t figure out
how to get it to empty the queue prior to closing the connection so as to
not discard any messages.

Any ideas?

   - Windows 8.1 x64
   - Python 2.7.7 x64
   - PyZMQ 4.0.4

*Marcus Ottosson*
konstruktion at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140620/0437f7f7/attachment.htm>

More information about the zeromq-dev mailing list