zmq async client server
2020.03.12 21:39
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
169 | 자동로그인 | WHRIA | 2008.05.17 | 7275 |
168 | Perfume | WHRIA | 2007.08.11 | 7276 |
167 | 슬라이스 | WHRIA | 2008.08.22 | 7288 |
166 | 오랜만에 medicalphoto 업데이트를 하려고 보니 | WHRIA | 2012.01.23 | 7321 |
165 | Bot | WHRIA | 2008.12.12 | 7339 |
164 | gold bar | WHRIA | 2008.10.19 | 7413 |
163 | Now I cover it. | WHRIA | 2007.08.03 | 7418 |
162 | 의전원 비용 | WHRIA | 2013.01.15 | 7433 |
161 | MedicalPhoto 1.0.5 | WHRIA | 2008.05.25 | 7458 |
160 | 열심히 일하기 | WHRIA | 2007.09.11 | 7478 |
159 | Boost lib 를 쓸까 MFC 를 쓸까 | WHRIA | 2012.12.10 | 7495 |
158 | Power | WHRIA | 2007.08.29 | 7498 |
157 | 학생 | WHRIA | 2007.09.09 | 7505 |
156 | 작전 [4] | WHRIA | 2009.06.23 | 7518 |
155 | PhotoPhoto 프로젝트 시작 | WHRIA | 2012.12.09 | 7524 |
REP 서버
import sys import asyncio import zmq import zmq.asyncio import random ctx = zmq.asyncio.Context() async def run_server(*ports): sock = ctx.socket(zmq.REP) for port in ports: sock.bind(f'tcp://*:{port}') while True: request = await sock.recv_string() print(f'RECEIVED:\t{request}') print(f'PROCESSING...') await asyncio.sleep(random.randrange(5,30) / 10) print(f'SENDING:\t{request}') await sock.send_string(request) if __name__ == '__main__': ports = sys.argv[1:] if len(sys.argv) > 1 else (5556,) asyncio.run(run_server(*ports))
REQ 클라이언트
import sys import asyncio import zmq import zmq.asyncio ctx = zmq.asyncio.Context() async def run_client(*ports): sock = ctx.socket(zmq.REQ) for port in ports: sock.connect(f'tcp://localhost:{port}') while True: line = input('>>') print(f'SENDING:\t{line}') await sock.send_string(line) reply = await sock.recv_string() print(f'RECEIVED:\t{reply}') if line == 'bye': break if __name__ == '__main__': ports = sys.argv[1:] if len(sys.argv) > 1 else (5556,) asyncio.run(run_client(*ports))