-The following is a simple example of how the a wormhole is
-created (rmr_wh_open) and then how ``rmr_wh_send_msg``
-function is used to send messages. Some error checking is
-omitted for clarity.
-
-
-::
-
-
- #include <rmr/rmr.h> // system headers omitted for clarity
-
- int main() {
- rmr_whid_t whid = -1; // wormhole id for sending
- void* mrc; //msg router context
- int i;
- rmr_mbuf_t* sbuf; // send buffer
- int count = 0;
- int norm_msg_size = 1500; // most messages fit in this size
-
- mrc = rmr_init( "43086", norm_msg_size, RMRFL_NONE );
- if( mrc == NULL ) {
- fprintf( stderr, "[FAIL] unable to initialise RMR environment\\n" );
- exit( 1 );
- }
-
- while( ! rmr_ready( mrc ) ) { // wait for routing table info
- sleep( 1 );
- }
-
- sbuf = rmr_alloc_msg( mrc, 2048 );
-
- while( 1 ) {
- if( whid < 0 ) {
- whid = rmr_wh_open( mrc, "localhost:6123" ); // open fails if endpoint refuses conn
- if( RMR_WH_CONNECTED( wh ) ) {
- snprintf( sbuf->payload, 1024, "periodic update from sender: %d", count++ );
- sbuf->len = strlen( sbuf->payload );
- sbuf = rmr_wh_call( mrc, whid, sbuf, 1000 ); // expect a response in 1s or less
- if( sbuf != NULL && sbuf->state = RMR_OK ) {
- sprintf( stderr, "response: %s\\n", sbuf->payload ); // assume they sent a string
- } else {
- sprintf( stderr, "response not received, or send error\\n" );
- }
- }
- }
-
- sleep( 5 );
- }
- }
-
+The following is a simple example of how the a wormhole is
+created (rmr_wh_open) and then how ``rmr_wh_send_msg``
+function is used to send messages. Some error checking is
+omitted for clarity.
+
+
+::
+
+
+ #include <rmr/rmr.h> // system headers omitted for clarity
+
+ int main() {
+ rmr_whid_t whid = -1; // wormhole id for sending
+ void* mrc; //msg router context
+ int i;
+ rmr_mbuf_t* sbuf; // send buffer
+ int count = 0;
+ int norm_msg_size = 1500; // most messages fit in this size
+
+ mrc = rmr_init( "43086", norm_msg_size, RMRFL_NONE );
+ if( mrc == NULL ) {
+ fprintf( stderr, "[FAIL] unable to initialise RMR environment\\n" );
+ exit( 1 );
+ }
+
+ while( ! rmr_ready( mrc ) ) { // wait for routing table info
+ sleep( 1 );
+ }
+
+ sbuf = rmr_alloc_msg( mrc, 2048 );
+
+ while( 1 ) {
+ if( whid < 0 ) {
+ whid = rmr_wh_open( mrc, "localhost:6123" ); // open fails if endpoint refuses conn
+ if( RMR_WH_CONNECTED( wh ) ) {
+ snprintf( sbuf->payload, 1024, "periodic update from sender: %d", count++ );
+ sbuf->len = strlen( sbuf->payload );
+ sbuf = rmr_wh_call( mrc, whid, sbuf, 1000 ); // expect a response in 1s or less
+ if( sbuf != NULL && sbuf->state = RMR_OK ) {
+ sprintf( stderr, "response: %s\\n", sbuf->payload ); // assume they sent a string
+ } else {
+ sprintf( stderr, "response not received, or send error\\n" );
+ }
+ }
+ }
+
+ sleep( 5 );
+ }
+ }
+