server端
#coding=utf-8
'''
Created on 2015-10-15
@author: kwsy2015
'''
import zmq
import time
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind('tcp://*:5555')
while True:
message = socket.recv()
print 'received request: ' ,message
time.sleep(1)
if message == 'hello':
socket.send('World')
else:
socket.send('success')
client端
#coding=utf-8
'''
Created on 2015-10-15
@author: kwsy2015
'''
import zmq
context = zmq.Context()
print 'connect to hello world server'
socket = context.socket(zmq.REQ)
socket.connect('tcp://localhost:5555')
for request in range(1,10):
print 'send ',request,'...'
socket.send('hello')
message = socket.recv()
print 'received reply ',request,'[',message,']'