zmq async client server
2020.03.12 21:39
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
1819 | 이건 비밀글이얍 | J | 2004.04.23 | 2 |
1818 | Odia - ଓଡ଼ିଆ | WHRIA | 2024.05.24 | 2 |
1817 | 아저씨에게 [1] | ^&^ | 2004.04.25 | 3 |
1816 | Russian - русский | WHRIA | 2024.05.24 | 3 |
1815 | Malay - bahasa Malaysia | WHRIA | 2024.05.24 | 4 |
1814 | Maltese - Malti | WHRIA | 2024.05.24 | 4 |
1813 | Norwegian - norsk | WHRIA | 2024.05.24 | 4 |
1812 | 아저씨~ [1] | ^&^ | 2004.05.15 | 5 |
1811 | Galician - galego | WHRIA | 2024.05.24 | 5 |
1810 | Gujarati - ગુજરાતી | WHRIA | 2024.05.24 | 5 |
1809 | Latvian - latviešu | WHRIA | 2024.05.24 | 5 |
1808 | Macedonian - македонски | WHRIA | 2024.05.24 | 5 |
1807 | Hungarian - magyar | WHRIA | 2024.05.24 | 6 |
1806 | Māori - te reo Māori | WHRIA | 2024.05.24 | 6 |
1805 | Nepali - नेपाली | WHRIA | 2024.05.24 | 6 |
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))