zmq async client server
2020.03.12 21:39
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
1639 | 제 홈페이지를 두배로 즐기려면??? | 한승석 | 2000.06.09 | 7069 |
1638 | 사랑에 빠지다 | WHRIA | 2007.07.06 | 7052 |
1637 | Clinical Study | WHRIA | 2007.08.13 | 7044 |
1636 | topsite | WHRIA | 2008.11.13 | 7027 |
1635 | medicalphoto 구연 | WHRIA | 2008.06.02 | 7001 |
1634 | 뻥스펙 | WHRIA | 2013.02.24 | 6990 |
1633 | hipass | WHRIA | 2008.11.09 | 6989 |
1632 | 토렌트 검색 site 만들었음 | WHRIA | 2012.02.14 | 6989 |
1631 | 거미 [3] | WHRIA | 2007.10.19 | 6980 |
1630 | 찜카드 | WHRIA | 2008.05.19 | 6971 |
1629 | 승석이형 너무 멋져요... | 김중희 | 2000.06.08 | 6964 |
1628 | Google Document | WHRIA | 2008.11.29 | 6924 |
1627 | 피델리티 차이나 | WHRIA | 2007.09.26 | 6922 |
1626 | adsense | WHRIA | 2009.01.16 | 6921 |
1625 | 오랜만에 글을 남김 | WHRIA | 2012.01.18 | 6901 |
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))