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