zmq async client server
2020.03.12 21:39
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
199 | 미남계 미녀계 | WHRIA | 2007.07.06 | 6788 |
198 | 법인 설립 | WHRIA | 2008.10.04 | 6820 |
197 | viber 를 써보니 | WHRIA | 2012.01.23 | 6823 |
196 | 테스트 | WHRIA | 2008.04.17 | 6884 |
195 | 오랜만에 글을 남김 | WHRIA | 2012.01.18 | 6898 |
194 | adsense | WHRIA | 2009.01.16 | 6914 |
193 | 피델리티 차이나 | WHRIA | 2007.09.26 | 6919 |
192 | Google Document | WHRIA | 2008.11.29 | 6922 |
191 | 승석이형 너무 멋져요... | 김중희 | 2000.06.08 | 6958 |
190 | 찜카드 | WHRIA | 2008.05.19 | 6971 |
189 | 거미 [3] | WHRIA | 2007.10.19 | 6973 |
188 | 토렌트 검색 site 만들었음 | WHRIA | 2012.02.14 | 6984 |
187 | 뻥스펙 | WHRIA | 2013.02.24 | 6985 |
186 | hipass | WHRIA | 2008.11.09 | 6988 |
185 | medicalphoto 구연 | WHRIA | 2008.06.02 | 6999 |
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))