zmq async client server
2020.03.12 21:39
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
1744 | Georgian - ქართული | WHRIA | 2024.05.24 | 0 |
1743 | Galician - galego | WHRIA | 2024.05.24 | 0 |
1742 | French - français | WHRIA | 2024.05.24 | 0 |
1741 | Finnish - suomi | WHRIA | 2024.05.24 | 0 |
1740 | Filipino - Filipino | WHRIA | 2024.05.24 | 3 |
1739 | Estonian - eesti | WHRIA | 2024.05.24 | 0 |
1738 | Esperanto - esperanto | WHRIA | 2024.05.24 | 2 |
1737 | Danish - dansk | WHRIA | 2024.05.24 | 0 |
1736 | Dutch - Nederlands | WHRIA | 2024.05.24 | 5 |
1735 | Danish - dansk | WHRIA | 2024.05.24 | 5 |
1734 | Czech - čeština | WHRIA | 2024.05.24 | 4 |
1733 | Croatian - hrvatski | WHRIA | 2024.05.24 | 2 |
1732 | Corsican - Corsican | WHRIA | 2024.05.24 | 6 |
1731 | Chinese (Taiwan) - Chinese (Taiwan) | WHRIA | 2024.05.24 | 1 |
1730 | Chinese (China) - 中文(中国) | WHRIA | 2024.05.24 | 2 |
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))