Skip to content

Instantly share code, notes, and snippets.

@esc
Created May 29, 2012 13:55
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 esc/2828508 to your computer and use it in GitHub Desktop.
Save esc/2828508 to your computer and use it in GitHub Desktop.
Example of Request Reply with zmq
import zmq
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://127.0.0.1:5000")
for i in range(10):
msg = "msg %s" % i
socket.send(msg)
print "Sending", msg
msg_in = socket.recv()
import time
import zmq
import sys
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://127.0.0.1:5000")
print("Listening for incoming messages.")
while True:
msg = socket.recv()
print("Processing %s" % msg, end='')
for i in range(5):
time.sleep(1)
print(".", end='')
sys.stdout.flush()
print('')
sys.stdout.flush()
socket.send(msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment