Created
May 29, 2012 13:55
-
-
Save esc/2828508 to your computer and use it in GitHub Desktop.
Example of Request Reply with zmq
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 | |
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() |
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 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