zmq async client server
2020.03.12 21:39
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
1639 | 참고 또 참고 | WHRIA | 2020.01.03 | 77 |
1638 | 식약청 메뉴 | WHRIA | 2020.05.14 | 77 |
1637 | DD-WRT 펌웨어로 버팔로 G450H 를 업그레이드 | WHRIA | 2015.11.22 | 78 |
1636 | lvm 축소 확장 [4] | WHRIA | 2020.01.13 | 79 |
1635 | image encryption [1] | WHRIA | 2020.04.24 | 79 |
1634 | startup | WHRIA | 2020.05.08 | 79 |
1633 | 드리블 | WHRIA | 2019.04.12 | 80 |
1632 | pytorch - caffe | WHRIA | 2019.12.19 | 80 |
1631 | 개명 | WHRIA | 2020.05.05 | 80 |
1630 | 이율초재 | WHRIA | 2014.10.20 | 81 |
1629 | 이사 감사 3년 변경등기 | WHRIA | 2015.12.02 | 81 |
1628 | WOL shutdown | WHRIA | 2016.01.22 | 81 |
1627 | AI papers [6] | WHRIA | 2023.03.02 | 81 |
1626 | 저녁 10시에 자동 종료 스크립트 | WHRIA | 2016.06.25 | 82 |
1625 | ebay 에서 비트코인 구입 | WHRIA | 2016.08.16 | 82 |
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))