zmq async client server
2020.03.12 21:39
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
1654 | 오랜만에 medicalphoto 업데이트를 하려고 보니 | WHRIA | 2012.01.23 | 7309 |
1653 | 슬라이스 | WHRIA | 2008.08.22 | 7277 |
1652 | 자동로그인 | WHRIA | 2008.05.17 | 7273 |
1651 | Perfume | WHRIA | 2007.08.11 | 7268 |
1650 | 버릴 것은 버리십시요. | WHRIA | 2007.08.09 | 7246 |
1649 | ssl | WHRIA | 2008.06.09 | 7239 |
1648 | 인생 헛살지는 않았다. | WHRIA | 2007.07.24 | 7235 |
1647 | 신한 | WHRIA | 2008.10.27 | 7232 |
1646 | 인생의 방향 | WHRIA | 2007.09.18 | 7220 |
1645 | inception | WHRIA | 2017.01.23 | 7201 |
1644 | go~ go~ go~ | WHRIA | 2008.08.19 | 7165 |
1643 | MS 가 리눅스개발자를 구한다는데 | WHRIA | 2012.01.29 | 7139 |
1642 | 피부암 | WHRIA | 2008.08.13 | 7138 |
1641 | Deep learning 기반 DEMO | WHRIA | 2018.09.16 | 7121 |
1640 | Medicalphoto 홈페이지 개편 | WHRIA | 2012.04.10 | 7118 |
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))