zmq async client server
2020.03.12 21:39
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
1654 | 넘 바쁘고 장난 아니다. | 으..죽겠다. | 2000.12.25 | 2078 |
1653 | *^^* | 구름 | 2001.01.02 | 2253 |
1652 | RE:119번 이야기 | 구름 | 2001.01.02 | 2097 |
1651 | 나양 | 호 | 2001.01.09 | 2179 |
1650 | `4월이야기`와 `8월의 크리스마스`의 공통점은? | soma | 2001.01.09 | 2334 |
1649 | 우와~감탄의 연발~! | 1004 | 2001.01.17 | 2437 |
1648 | 지나가는길에... | 임연경 | 2001.01.24 | 2254 |
1647 | 넘 멋쪄요!!! | 송혜린 | 2001.01.26 | 2080 |
1646 | Re: 우와~감탄의 연발~! | 한승석 | 2001.01.27 | 2085 |
1645 | Re: 지나가는길에... | 한승석 | 2001.01.27 | 2079 |
1644 | Re: 넘 멋쪄요!!! | 한승석 | 2001.01.27 | 2076 |
1643 | Re: `4월이야기`와 `8월의 크리스마스`의 공통점은? | 한승석 | 2001.01.27 | 2081 |
1642 | order | 서권 | 2001.02.11 | 3278 |
1641 | 여기는 신촌 | 최평균 | 2001.02.11 | 2078 |
1640 | 이오더 말이지... | 윤재원 | 2001.02.13 | 2849 |
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))