Skip to content

Instantly share code, notes, and snippets.

@dln
Created June 28, 2011 14:17
Show Gist options
  • Save dln/1051221 to your computer and use it in GitHub Desktop.
Save dln/1051221 to your computer and use it in GitHub Desktop.
ZeroMQ echo server (REP) for testing.
#!/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