Create a gist now

Instantly share code, notes, and snippets.

ZeroMQ
import argparse
import zmq
from time import sleep
parser = argparse.ArgumentParser(description='zeromq server/client')
parser.add_argument('--bar')
args = parser.parse_args()
if args.bar:
count = 0
# client
while True:
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect('tcp://127.0.0.1:5555')
socket.send(args.bar + " - " + str(count))
count += 1
msg = socket.recv()
print msg
if (args.bar == 'test1'):
sleep(0.1)
else:
sleep(0.1)
import argparse
import zmq
from time import sleep
# server
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind('tcp://127.0.0.1:5555')
while True:
msg = socket.recv()
if msg == 'zeromq':
socket.send('ah ha!')
else:
socket.send(msg + 'server Message')
print msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment