zmq async client server
2020.03.12 21:39
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
169 | center % crop | WHRIA | 2018.12.27 | 70 |
168 | fcitx | WHRIA | 2020.04.05 | 70 |
167 | psexec | WHRIA | 2016.07.28 | 69 |
166 | LG 글로벌 | WHRIA | 2019.01.31 | 68 |
» | zmq async client server [1] | WHRIA | 2020.03.12 | 68 |
164 | bay trail ubuntu 20.04 [1] | WHRIA | 2020.12.24 | 68 |
163 | 싸이월드도 없어지는구나 | WHRIA | 2015.10.10 | 66 |
162 | linux raid | WHRIA | 2019.11.30 | 66 |
161 | raid monitor | WHRIA | 2019.12.15 | 66 |
160 | raid 6 rebuild | WHRIA | 2020.01.07 | 66 |
159 | color pallate | WHRIA | 2019.04.07 | 64 |
158 | test | WHRIA | 2020.12.03 | 64 |
157 | disk error | WHRIA | 2023.02.16 | 64 |
156 | swap memory | WHRIA | 2019.03.14 | 63 |
155 | 서피스 3 질렀다. ㅎㅎ | WHRIA | 2015.12.15 | 62 |
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))