zmq async client server
2020.03.12 21:39
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
169 | 나양 | 호 | 2001.01.09 | 2177 |
168 | RE:119번 이야기 | 구름 | 2001.01.02 | 2090 |
167 | *^^* | 구름 | 2001.01.02 | 2252 |
166 | 넘 바쁘고 장난 아니다. | 으..죽겠다. | 2000.12.25 | 2074 |
165 | 승석 뭐하노? | 호 | 2000.12.25 | 2079 |
164 | 허거덕 | 재호 | 2000.12.22 | 2077 |
163 | 승써가 | 가을동화 | 2000.11.29 | 2241 |
162 | 으~승석아... | 신나남 | 2000.11.27 | 2255 |
161 | 내과 홈페이지 노가다가 일부 끝나다. | 한승석 | 2000.11.19 | 2126 |
160 | 승석아... | 신나남 | 2000.11.16 | 2077 |
159 | 야호.. CDSPACE 이름 짓기에 당첨.. | 한승석 | 2000.11.14 | 2384 |
158 | 홈피 잘 구경하고 가요 *^^* | viere♥ | 2000.11.13 | 2080 |
157 | 야... | 신나남 | 2000.11.06 | 2553 |
156 | 이런 홈페이지는 처음 봐요. | 최훈성 | 2000.11.03 | 2192 |
155 | 요즘 나는 | 한승석 | 2000.10.30 | 2078 |
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))