Skip to content

Instantly share code, notes, and snippets.

@whardier
Created March 9, 2012 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whardier/2007883 to your computer and use it in GitHub Desktop.
Save whardier/2007883 to your computer and use it in GitHub Desktop.
Multicast message pub/sub test
import zmq
import uuid
import random
context = zmq.Context()
recv = context.socket(zmq.SUB)
recv.setsockopt(zmq.SUBSCRIBE, '')
recv.connect('epgm://eth0;224.0.0.1:5555')
send = context.socket(zmq.PUB)
send.bind('epgm://eth0;224.0.0.1:5555')
poller = zmq.Poller()
poller.register(recv, zmq.POLLIN)
myuuid = uuid.uuid4()
while True:
socks = dict(poller.poll(10))
if socks.get(recv) == zmq.POLLIN:
recv_message = recv.recv_pyobj()
print 'RECV', recv_message
if not random.randint(0,100):
msg = (myuuid, random.random())
send.send_pyobj(msg)
print 'SEND', msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment