Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pass interactively entered data to a server process using pyzmq
#!/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
You can’t perform that action at this time.