python zmq 통신 사용

967 단어 서버 개발
서버 엔 드
#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')

클 라 이언 트 엔 드
#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,']'

좋은 웹페이지 즐겨찾기