zmq async client server
2020.03.12 21:39
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
169 | webapp [1] | WHRIA | 2020.05.10 | 92 |
168 | android / capture and crop [5] | WHRIA | 2020.05.10 | 52 |
167 | 식약청 메뉴 | WHRIA | 2020.05.14 | 82 |
166 | CE | WHRIA | 2020.05.17 | 57 |
165 | encfs | WHRIA | 2020.05.17 | 36064 |
164 | single file encrypt decrypt | WHRIA | 2020.05.17 | 1783 |
163 | 영어로 숫자 표현 | WHRIA | 2020.05.28 | 4466 |
162 | BERT | WHRIA | 2020.06.10 | 3286 |
161 | MS bot framework [3] | WHRIA | 2020.06.13 | 116 |
160 | regression model [6] | WHRIA | 2020.06.18 | 177 |
159 | 바이두 | WHRIA | 2020.06.20 | 686 |
158 | reddit downloader | WHRIA | 2020.06.21 | 221 |
157 | resnest50 caffe | WHRIA | 2020.06.21 | 168 |
156 | caffe hdf5 error | WHRIA | 2020.06.22 | 190 |
155 | 할일 | WHRIA | 2020.06.24 | 1528 |
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))