3 ==================================================================================
4 Copyright (c) 2019 Nokia
5 Copyright (c) 2018-2019 AT&T Intellectual Property.
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18 ==================================================================================
21 .** example sender code
23 &h2(Receive and Send Sample)
24 The following code snippet receives messages and responds to the sender
25 if the message type is odd.
26 The code illustrates how the received message may be used to return
27 a message to the source.
28 Variable type definitions are omitted for clarity and should be obvious.
31 It should also be noted that
32 things like the message type which id returned to the sender (99) is
33 a random value that these applications would have agreed on in advance
34 and is &bold(not) an RMR definition.
40 mrc = rmr_init( listen_port, MAX_BUF_SZ, RMRFL_NOFLAGS );
41 rmr_set_stimeout( mrc, 1 ); // allow RMR to retry failed sends for ~1ms
43 while( ! rmr_ready( mrc ) ) { // we send, therefore we need a route table
47 mbuf = NULL; // ensure our buffer pointer is nil for 1st call
50 mbuf = rmr_rcv_msg( mrc, mbuf ); // wait for message
52 if( mbuf == NULL || mbuf->state != RMR_OK ) {
56 if( mbuf->mtype % 2 ) { // respond to odd message types
57 plen = rmr_payload_size( mbuf ); // max size
59 // reset necessary fields in msg
60 mbuf->mtype = 99; // response type
61 mbuf->sub_id = RMR_VOID_SUBID; // we turn subid off
62 mbuf->len = snprintf( mbuf->payload, plen, "pong: %s", get_info() );
64 mbuf = rmr_rts_msg( mrc, mbuf ); // return to sender
65 if( mbuf == NULL || mbuf->state != RMR_OK ) {
66 fprintf( stderr, "return to sender failed\n" );
71 fprintf( stderr, "abort: receive failure\n" );