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