-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreq.py
36 lines (27 loc) · 960 Bytes
/
req.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import argparse
import logging
import time
import msgpack
import zmq
LOG = logging.getLogger(__name__)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--connect", help="host to connect",
required=True, action="store", type=str, metavar="URL")
args = parser.parse_args()
lognum = getattr(logging, "INFO")
logging.basicConfig(format='{asctime} {levelname} {module} {message}',
style='{', level=lognum)
context = zmq.Context()
sock = context.socket(zmq.REQ)
sock.connect(args.connect)
req_msg = {"key1": "val1", "key2": 2}
while True:
try:
sock.send(msgpack.packb(req_msg))
LOG.info("Sent as REQ: %s", req_msg)
recv_msg = msgpack.unpackb(sock.recv(), encoding='utf-8')
LOG.info("Received as REP: %s", recv_msg)
time.sleep(1)
except KeyboardInterrupt:
break