zmq async client server
2020.03.12 21:39
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
1654 | bay trail ubuntu 20.04 [1] | WHRIA | 2020.12.24 | 68 |
1653 | psexec | WHRIA | 2016.07.28 | 70 |
1652 | center % crop | WHRIA | 2018.12.27 | 70 |
1651 | 지급명세서 | WHRIA | 2015.10.14 | 71 |
1650 | 정량화 논문들 | WHRIA | 2023.02.16 | 71 |
1649 | fcitx | WHRIA | 2020.04.05 | 72 |
1648 | plum | WHRIA | 2020.04.03 | 73 |
1647 | chat GPT | WHRIA | 2023.02.16 | 73 |
1646 | MDR - PL | WHRIA | 2023.05.11 | 73 |
1645 | 증시의 허풍 예언들 | WHRIA | 2015.11.20 | 74 |
1644 | CIDR 표기법 [1] | WHRIA | 2020.03.12 | 74 |
1643 | pstools | WHRIA | 2016.07.31 | 75 |
1642 | retinanet nvidia [3] | WHRIA | 2020.01.12 | 75 |
1641 | php 세션 로그인 | WHRIA | 2020.04.24 | 75 |
1640 | rsynccp | WHRIA | 2023.02.20 | 75 |
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))