Rename health_ck support binary to rmr_probe
[ric-plt/lib/rmr.git] / src / bindings / rmr-python / examples / receive.py
1 # ==================================================================================
2 #       Copyright (c) 2019 Nokia
3 #       Copyright (c) 2018-2019 AT&T Intellectual Property.
4 #
5 #   Licensed under the Apache License, Version 2.0 (the "License");
6 #   you may not use this file except in compliance with the License.
7 #   You may obtain a copy of the License at
8 #
9 #          http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #   Unless required by applicable law or agreed to in writing, software
12 #   distributed under the License is distributed on an "AS IS" BASIS,
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #   See the License for the specific language governing permissions and
15 #   limitations under the License.
16 # ==================================================================================
17 from setuptools import setup, find_packages
18
19 from rmr import rmr
20 import time
21 import sys
22 import signal
23
24
25 # Demonstrate NNG cleanup
26 def signal_handler(sig, frame):
27     print('SIGINT received! Cleaning up rmr')
28     rmr.rmr_close(mrc)
29     print("Byeee")
30     sys.exit(0)
31
32
33 # init rmr
34 mrc = rmr.rmr_init("4560".encode('utf-8'), rmr.RMR_MAX_RCV_BYTES, 0x00)
35 while rmr.rmr_ready(mrc) == 0:
36     time.sleep(1)
37     print("not yet ready")
38 rmr.rmr_set_stimeout(mrc, 2)
39
40 # capture ctrl-c
41 signal.signal(signal.SIGINT, signal_handler)
42
43
44 sbuf = None
45 while True:
46     print("Waiting for a message, will timeout after 2000ms")
47     sbuf = rmr.rmr_torcv_msg(mrc, sbuf, 2000)
48     summary = rmr.message_summary(sbuf)
49     if summary['message state'] == 12:
50         print("Nothing received =(")
51     else:
52         print("Message received!: {}".format(summary))
53         val = b"message recieved OK yall!"
54         rmr.set_payload_and_length(val, sbuf)
55         sbuf = rmr.rmr_rts_msg(mrc, sbuf)
56     time.sleep(1)