zmq async client server
2020.03.12 21:39
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
1744 | Sinhala - සිංහල | WHRIA | 2024.05.24 | 0 |
1743 | Slovak - slovenčina | WHRIA | 2024.05.24 | 0 |
1742 | Slovenian - slovenščina | WHRIA | 2024.05.24 | 0 |
1741 | Somali - Soomaali | WHRIA | 2024.05.24 | 0 |
1740 | Southern Sotho - Southern Sotho | WHRIA | 2024.05.24 | 0 |
1739 | Spanish - español | WHRIA | 2024.05.24 | 0 |
1738 | Sundanese - Basa Sunda | WHRIA | 2024.05.24 | 0 |
1737 | Swahili - Kiswahili | WHRIA | 2024.05.24 | 0 |
1736 | Swedish - svenska | WHRIA | 2024.05.24 | 0 |
1735 | Tajik - тоҷикӣ | WHRIA | 2024.05.24 | 0 |
1734 | Tamil - தமிழ் | WHRIA | 2024.05.24 | 0 |
1733 | Telugu - తెలుగు | WHRIA | 2024.05.24 | 0 |
1732 | Thai - ไทย | WHRIA | 2024.05.24 | 0 |
1731 | Turkish - Türkçe | WHRIA | 2024.05.24 | 0 |
1730 | Ukrainian - українська | WHRIA | 2024.05.24 | 0 |
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))