Created
March 9, 2012 18:24
-
-
Save whardier/2007883 to your computer and use it in GitHub Desktop.
Multicast message pub/sub test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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