zmq async client server
2020.03.12 21:39
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
199 | Re: ^^*v 저 또 왔어요 | 한승석 | 2001.04.07 | 2018 |
198 | 노 벨 | 채영광 | 2001.04.04 | 2108 |
197 | ^^*v 저 또 왔어요 | Schauberger | 2001.03.30 | 2088 |
196 | Re: [TIP] 유동 IP 로 서버 만드는 법 | 애국자 | 2001.03.29 | 2178 |
195 | 씨팡 | 씨팡 | 2001.03.28 | 2119 |
194 | [TIP] 유동 IP 로 서버 만드는 법 | 한승석 | 2001.03.24 | 2272 |
193 | Re: 봄맞이 새단장? *^^* | 한승석 | 2001.03.05 | 2094 |
192 | 민물장어의 꿈 | soma | 2001.03.05 | 3420 |
191 | 봄맞이 새단장? *^^* | soma | 2001.03.05 | 2085 |
190 | 앗!! 주소가 더 추가되었습니다. | 한승석 | 2001.03.03 | 2119 |
189 | [TIP] 오른쪽 마우스 BLOCK 뚫기 | 한승석 | 2001.03.03 | 2454 |
188 | 홈페이지 주소 (hospital.pe.ky hospital.oo.co.kr) 입니다. | 한승석 | 2001.03.03 | 2091 |
187 | 현관문은... | 한승석 | 2001.03.03 | 2077 |
186 | 현관문이 좀......(홈피대문) | Schauberger | 2001.03.03 | 2076 |
185 | FTP 서버를 열었습니다. | 한승석 | 2001.03.02 | 2066 |
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))