Created
April 11, 2012 18:07
-
-
Save lebedov/2361034 to your computer and use it in GitHub Desktop.
Pass interactively entered data to a server process using pyzmq
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
#!/usr/bin/env python | |
""" | |
Pass interactively entered data to a server process using pyzmq. | |
""" | |
import zmq | |
import multiprocessing as mp | |
def server_func(): | |
context = zmq.Context() | |
socket = context.socket(zmq.REP) | |
socket.bind("tcp://*:5555") | |
while True: | |
message = socket.recv() | |
print "Server: ", message | |
socket.send("server reply") | |
if message == 'quit': | |
break | |
def client_func(): | |
context = zmq.Context() | |
socket = context.socket(zmq.REQ) | |
socket.connect("tcp://localhost:5555") | |
while True: | |
data = raw_input('? ') | |
socket.send(data) | |
if data == 'quit': | |
break | |
message = socket.recv() | |
print "Client: ", message | |
server = mp.Process(target=server_func) | |
server.start() | |
client_func() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment