zmq async client server
2020.03.12 21:39
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
1819 | Afrikaans - Afrikaans | WHRIA | 2024.05.24 | 0 |
1818 | Albanian - shqip | WHRIA | 2024.05.24 | 0 |
1817 | Amharic - አማርኛ | WHRIA | 2024.05.24 | 0 |
1816 | Arabic - العربية | WHRIA | 2024.05.24 | 0 |
1815 | Armenian - հայերեն | WHRIA | 2024.05.24 | 0 |
1814 | Azerbaijani - azərbaycan | WHRIA | 2024.05.24 | 0 |
1813 | Bangla - বাংলা | WHRIA | 2024.05.24 | 0 |
1812 | Basque - euskara | WHRIA | 2024.05.24 | 0 |
1811 | Belarusian - беларуская | WHRIA | 2024.05.24 | 0 |
1810 | Bosnian - bosanski | WHRIA | 2024.05.24 | 0 |
1809 | Burmese - မြန်မာ | WHRIA | 2024.05.24 | 0 |
1808 | Catalan - català | WHRIA | 2024.05.24 | 0 |
1807 | Chinese (China) - 中文(中国) | WHRIA | 2024.05.24 | 0 |
1806 | Chinese (Taiwan) - Chinese (Taiwan) | WHRIA | 2024.05.24 | 0 |
1805 | Corsican - Corsican | 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))