zmq async client server
2020.03.12 21:39
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
1819 | mAP 계산법 | WHRIA | 2019.02.24 | 45576 |
1818 | epitope spreading | han | 2006.05.09 | 41030 |
1817 | encfs | WHRIA | 2020.05.17 | 36001 |
1816 | Heinrich Law (1:29:300 Law) | WHRIA | 2007.08.12 | 25000 |
1815 | 일본 주소 [2] | WHRIA | 2008.06.28 | 24030 |
1814 | 사주팔자 프로그램 | 한승석 | 2003.02.16 | 20335 |
1813 | simple adblock | WHRIA | 2012.04.13 | 18115 |
1812 | 도란사민 | WHRIA | 2011.04.19 | 18102 |
1811 | 탤런트 이윤지씨와 함께 | WHRIA | 2010.02.04 | 17046 |
1810 | penicillin | han | 2003.12.10 | 15717 |
1809 | SSH tunnel | WHRIA | 2007.10.01 | 15087 |
1808 | geexbox [1] | han | 2006.12.01 | 14611 |
1807 | 아이피부과 개원 | WHRIA | 2010.01.18 | 14441 |
1806 | 세무회계 | WHRIA | 2010.01.31 | 14404 |
1805 | 증명사진 | WHRIA | 2010.03.14 | 14336 |
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))