/** * Client-side function * * @param argc Number of arguments * @param argv List of the arguments (array) * @return 0 if no error */ static int client( int argc, char *argv[] ) { /* Connect to one messip server */ messip_init( ); display( "start process\n" ); messip_cnx_t *cnx = messip_connect( NULL, "ex9/p2", MESSIP_NOTIMEOUT ); if ( !cnx ) cancel( "Unable to find messip server\n" ); /* Localize channel 'one' */ messip_channel_t *ch = messip_channel_connect( cnx, "one", MESSIP_NOTIMEOUT ); if ( !ch ) cancel( "Unable to localize channel '%s'\n", "one" ); display( "Channel located - remote_id=%s\n", ch->remote_id ); /* Send a message on channel 'one' */ display( "sending now a message (len=%d)to the server...\n", sizeof(msg1) ); char rec_buff[ 80 ]; memset( rec_buff, 0, sizeof( rec_buff ) ); int32_t answer; int status = messip_send( ch, 1, msg1, sizeof(msg1), &answer, rec_buff, sizeof( rec_buff ), MESSIP_NOTIMEOUT ); display( "send status=%d received back=%d-%d:'%s' answer=%d id=%s\n", status, ch->datalen, ch->datalenr, rec_buff, answer, ch->remote_id ); assert(answer == 3005); display( "Now waiting 20 seconds...\n" ); delay( 20000 ); /* */ status = messip_send( ch, 1961, msg2, sizeof(msg2), &answer, rec_buff, sizeof( rec_buff ), MESSIP_NOTIMEOUT ); display( "send status=%d received back=%d-%d:'%s' answer=%d id=%s\n", status, ch->datalen, ch->datalenr, rec_buff, answer, ch->remote_id ); assert(answer == 2003); /* Disconnect from this channel */ messip_channel_disconnect( ch, MESSIP_NOTIMEOUT ); return 0; } // client
/** * Client-side function * * @param argc Number of arguments * @param argv List of the arguments (array) * @return 0 if no error */ static int client( int argc, char *argv[] ) { /* Connect to one messip server */ messip_init( ); display( "start process\n" ); messip_cnx_t *cnx = messip_connect( NULL, "ex1/p2", MESSIP_NOTIMEOUT ); if ( !cnx ) cancel( "Unable to find messip server\n" ); /* Localize channel 'one' */ messip_channel_t *ch = messip_channel_connect( cnx, "one", MESSIP_NOTIMEOUT ); if ( !ch ) cancel( "Unable to localize channel '%s'\n", "one" ); display( "Channel located - remote_id=%s\n", ch->remote_id ); /* Send a 1st message on channel 'one' */ char rec_buff[ 100 ]; memset( rec_buff, 0, sizeof(rec_buff) ); int32_t answer; int status = messip_send( ch, 1, "Hello1", 7, &answer, rec_buff, sizeof(rec_buff), MESSIP_NOTIMEOUT ); display( "send status=%d received back='%s' remote_id=%s\n", status, rec_buff, ch->remote_id ); /* Send a 2nd message on channel 'one' */ memset( rec_buff, 0, sizeof(rec_buff) ); status = messip_send( ch, 3, "Hello2", 7, &answer, rec_buff, sizeof(rec_buff), MESSIP_NOTIMEOUT ); display( "send status=%d received back='%s' remote_id=%s\n", status, rec_buff, ch->remote_id ); return 0; } // client
/** * Client-side function * * @param argc Number of arguments * @param argv List of the arguments (array) * @return 0 if no error */ static int client( int argc, char *argv[] ) { /*--- Connect to one messip server ---*/ messip_init( ); display( "start process\n" ); messip_cnx_t *cnx = messip_connect( NULL, "ex8/p2", MESSIP_NOTIMEOUT ); if ( !cnx ) cancel( "Unable to find messip server\n" ); /*--- Localize channel 'one' ---*/ messip_channel_t *ch = messip_channel_connect( cnx, "one", MESSIP_NOTIMEOUT ); if ( !ch ) cancel( "Unable to localize channel '%s'\n", "one" ); display( "Channel located - remote_id=%s\n", ch->remote_id ); /*--- Send a message on channel 'one' ---*/ display( "sending now a message to the server...\n" ); char rec_buff[ 80 ]; memset( rec_buff, 0, sizeof( rec_buff ) ); int32_t answer; int status = messip_send( ch, 1961, "Hello", 6, &answer, rec_buff, sizeof( rec_buff ), MESSIP_NOTIMEOUT ); display( "send status=%d received back=%d-%d:'%s' answer=%d id=%s\n", status, ch->datalen, ch->datalenr, rec_buff, answer, ch->remote_id ); assert( answer == 3005 ); /*--- Then 2 ping messages ---*/ delay( 3000 ); display( "Waiting for ping...\n" ); messip_channel_ping( ch, 5000 ); delay( 3000 ); messip_channel_ping( ch, 5000 ); display( "Waiting for ping...\n" ); /*--- Disconnect from this channel ---*/ messip_channel_disconnect( ch, MESSIP_NOTIMEOUT ); return 0; } // client
int main(int argc, char *argv[]) { messip_channel_t *ch; #if !defined(ONEWAY_MESSAGE) char rec_buff[80]; #endif char snd_buff[80]; int32_t answer; int i; double d; #if defined(__QNXNTO__) uint64_t cps, cycle1, cycle2, ncycles; #else /*!__QNXNTO__ */ struct timespec before, after; #endif /* __QNXNTO__ */ int q = 0; #if 1 struct sched_param param; if ((param.sched_priority=sched_get_priority_max(SCHED_FIFO)) == -1) fprintf (stderr, "sched_get_priority_max(): %s\n", strerror (errno)); if (( sched_setscheduler(0, SCHED_FIFO, ¶m)) == -1) fprintf (stderr, "sched_setscheduler(): %s\n", strerror (errno)); #endif #if defined(__QNXNTO__) /* find out how many cycles per second */ cps = SYSPAGE_ENTRY(qtime)->cycles_per_sec; printf( "This system has %lld cycles/sec.\n",cps ); #endif /* __QNXNTO__ */ do { // Locate the channel where to send message to ch = messip_channel_connect(NULL, (argc < 2) ? "one" : argv[1], MESSIP_NOTIMEOUT); assert(ch != NULL); #if 1 // Send messages for (i = 0; i < SEND_TIMES; i++) { sprintf(snd_buff, "%d", i); #if defined(__QNXNTO__) cycle1=ClockCycles(); #else /*!__QNXNTO__ */ clock_gettime(CLOCK_REALTIME, &before); #endif /* __QNXNTO__ */ #if defined(ONEWAY_MESSAGE) messip_send(ch, 100, 200, (void *) snd_buff, strlen(snd_buff)+1, // Type=100 Subtype=200 &answer, NULL, -1, MESSIP_NOTIMEOUT); #else messip_send(ch, 100, 200, (void *) snd_buff, strlen(snd_buff)+1, // Type=100 Subtype=200 &answer, rec_buff, sizeof(rec_buff), MESSIP_NOTIMEOUT); #endif #if defined(__QNXNTO__) cycle2=ClockCycles(); ncycles=cycle2-cycle1; d=(double)ncycles/cps; usleep(1000); #else /*!__QNXNTO__ */ clock_gettime(CLOCK_REALTIME, &after); d = (after.tv_sec+after.tv_nsec/1e9) -(before.tv_sec+before.tv_nsec/1e9); #endif /* __QNXNTO__ */ #if defined(ONEWAY_MESSAGE) printf("%.9f\n", d); #else printf("%s: %.9f\n", rec_buff, d); #endif } if (i < SEND_TIMES) { perror("messip_send()"); } #endif messip_channel_disconnect(ch, MESSIP_NOTIMEOUT); } while(q++ < 3); return 0; }
/** * Client-side function * * @param argc Number of arguments * @param argv List of the arguments (array) * @return 0 if no error */ static int client( int argc, char *argv[] ) { /*--- Connect to one messip server ---*/ messip_set_log_level( MESSIP_LOG_ERROR | MESSIP_LOG_WARNING | MESSIP_LOG_INFO /* | MESSIP_LOG_INFO_VERBOSE | MESSIP_LOG_DEBUG */ ); messip_init( ); display( "start process\n" ); messip_cnx_t *cnx = messip_connect( NULL, "ex1/p2", MESSIP_NOTIMEOUT ); if ( !cnx ) cancel( "Unable to find messip manager\n" ); /*--- Localize channel 'one' ---*/ messip_channel_t *ch = messip_channel_connect( cnx, "one", MESSIP_NOTIMEOUT ); if ( !ch ) cancel( "Unable to localize channel '%s'\n", "one" ); display( "Channel located - remote_id=%s\n", ch->remote_id ); /*--- Send a 1st message on channel 'one' ---*/ display( "sending now a 1st message to the server...\n" ); int32_t answer; char rec_buff[80]; int status = messip_send( ch, 1961, "Hello", 6, &answer, rec_buff, sizeof( rec_buff ), MESSIP_NOTIMEOUT ); if ( status == -1 ) { fprintf( stderr, "%s %d:\n\tError on send message #1 on channel '%s', errno=%d\n", __FILE__, __LINE__, "one", errno ); return -1; } display( "send status=%d received back=%d-%d:'%s' answer=%d id=%s\n", status, ch->datalen, ch->datalenr, rec_buff, answer, ch->remote_id ); assert( answer == 3005 ); /*--- Send a 2nd message on channel 'one' ---*/ display( "sending now a 2nd message to the server...\n" ); char *rbuff; status = messip_send( ch, 123, "Unix", 5, &answer, &rbuff, 0, MESSIP_NOTIMEOUT ); display( "send status=%d received back=%d-%d:'%s' answer=%d id=%s\n", status, ch->datalen, ch->datalenr, rbuff, answer, ch->remote_id ); if ( status == -1 ) { fprintf( stderr, "%s %d:\n\tError on send message #2 on channel '%s', errno=%d\n", __FILE__, __LINE__, "one", errno ); return -1; } assert( answer == 256 ); free( rbuff ); /*--- Then 2 ping messages ---*/ delay( 3000 ); display( "Waiting for ping...\n" ); status = messip_channel_ping( ch, 5000 ); display( "Status ping = %d\n", status ); delay( 3000 ); display( "Waiting for ping...\n" ); status = messip_channel_ping( ch, 5000 ); display( "Status ping = %d\n", status ); /*--- Disconnect from this channel ---*/ status = messip_channel_disconnect( ch, MESSIP_NOTIMEOUT ); display( "Status disconnect channel = %d\n", status ); return 0; } // client