Created
June 28, 2011 14:17
-
-
Save dln/1051221 to your computer and use it in GitHub Desktop.
ZeroMQ echo server (REP) for testing.
This file contains hidden or 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
#!/usr/bin/env python | |
import sys | |
import zmq | |
ctx = zmq.Context() | |
poll = zmq.Poller() | |
addrs = {} | |
for addr in sys.argv[1:]: | |
print "Binding", addr | |
sock = ctx.socket(zmq.REP) | |
addrs[sock] = addr | |
sock.bind(addr) | |
poll.register(sock, zmq.POLLIN) | |
while True: | |
print "Running..." | |
items = dict(poll.poll()) | |
for sock in items: | |
msg = sock.recv_multipart() | |
addr = addrs[sock] | |
print "I (%s): %r" % (addr, msg) | |
offs = msg.index('') | |
reply = ['ECHO'] + msg | |
print "O (%s): %r" % (addr, reply) | |
sock.send_multipart(reply) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment