zmq async client server
2020.03.12 21:39
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
199 | WOL shutdown | WHRIA | 2016.01.22 | 85 |
198 | 저녁 10시에 자동 종료 스크립트 | WHRIA | 2016.06.25 | 85 |
197 | windows softraid monitor | WHRIA | 2019.12.19 | 85 |
196 | sroc [1] | WHRIA | 2020.12.10 | 84 |
195 | ebay 에서 비트코인 구입 | WHRIA | 2016.08.16 | 83 |
194 | 힘든 하루하루 | WHRIA | 2016.09.30 | 83 |
193 | 이율초재 | WHRIA | 2014.10.20 | 82 |
192 | 넌센스 퀴즈 | WHRIA | 2016.09.04 | 82 |
191 | tab 구조 html | WHRIA | 2020.06.28 | 82 |
190 | AI papers [6] | WHRIA | 2023.03.02 | 82 |
189 | lvm 축소 확장 [4] | WHRIA | 2020.01.13 | 81 |
188 | 개명 | WHRIA | 2020.05.05 | 81 |
187 | startup | WHRIA | 2020.05.08 | 81 |
186 | 드리블 | WHRIA | 2019.04.12 | 80 |
185 | pytorch - caffe | WHRIA | 2019.12.19 | 80 |
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))