Created
March 11, 2011 06:38
-
-
Save minrk/865547 to your computer and use it in GitHub Desktop.
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
# | |
# Hello World client in Python | |
# Connects REQ socket to tcp://localhost:5555 | |
# Sends "Hello" to server, expects "World" back | |
# | |
import zmq | |
context = zmq.Context() | |
# Socket to talk to server | |
print ("Connecting to hello world server...") | |
socket = context.socket(zmq.REQ) | |
socket.connect ("tcp://localhost:5555") | |
# Do 10 requests, waiting each time for a response | |
for request in range (1,10): | |
print ("Sending request %", request, "...") | |
socket.send (b"Hello") | |
# Get the reply. | |
message = socket.recv() | |
print ("Received reply ", request, "[", message.decode(), "]") |
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
# | |
# Hello World server in Python | |
# Binds REP socket to tcp://*:5555 | |
# Expects "Hello" from client, replies with "World" | |
# | |
import zmq | |
import time | |
context = zmq.Context() | |
socket = context.socket(zmq.REP) | |
socket.bind("tcp://*:5555") | |
while True: | |
# Wait for next request from client | |
message = socket.recv() | |
print ("Received request: ", message) | |
# Do some 'work' | |
time.sleep (1) # Do some 'work' | |
# Send reply back to client | |
socket.send(b"World") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment