Exemplo n.º 1
0
Arquivo: p.c Projeto: osingla/messip
/**
 *  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
Exemplo n.º 2
0
Arquivo: p.c Projeto: osingla/messip
/**
 *  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
Exemplo n.º 3
0
Arquivo: p.c Projeto: osingla/messip
/**
 *  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
Exemplo n.º 4
0
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, &param)) == -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;

}
Exemplo n.º 5
0
Arquivo: p.c Projeto: osingla/messip
static int server( int argc, char *argv[] ) {
	/*--- Connect to one messip server ---*/
	display( "Start process\n" );
	messip_init( );
    messip_cnx_t *cnx = messip_connect( NULL, "ex8/p1", MESSIP_NOTIMEOUT );
    if ( !cnx ) 
        cancel( "Unable to find messip server\n" );

	/*--- Create 5 channels ---*/
	messip_channel_t *ch1 = create_channel( cnx, "one" );
	messip_channel_t *ch2 = create_channel( cnx, "two" );
	messip_channel_t *ch3 = create_channel( cnx, "three" );
	messip_channel_t *ch4 = create_channel( cnx, "four" );
	messip_channel_t *ch5 = create_channel( cnx, "five" );

	/*--- Now delete the 3rd channel ---*/
	display( "Channels have been created. Waiting 15 seconds...\n" );
	delay( 15000 );
	int status = messip_channel_delete( ch3, MESSIP_NOTIMEOUT );
	display( "messip_channel_delete #3: status=%d\n", status );
	assert(status == 0);
	delay( 15000 );

	/*--- Attach to channel four ---*/
	messip_channel_t *xch4 = messip_channel_connect( cnx, "four", MESSIP_NOTIMEOUT );
	assert(xch4 != NULL);
	status = messip_channel_delete( ch4, MESSIP_NOTIMEOUT );
	display( "messip_channel_delete #4: status=%d\n", status );
	assert(status == 1);

	/*--- Now delete the 4th channel ---*/
	status = messip_channel_disconnect( xch4, MESSIP_NOTIMEOUT );
	display( "messip_channel_disconnect #4: status=%d\n", status );
	status = messip_channel_delete( ch4, MESSIP_NOTIMEOUT );
	display( "messip_channel_delete #4: status=%d\n", status );
	assert(status == 0);

	/*--- Now wait for one message on this on channel ---*/
	display( "Wait now 10 seconds...\n" );
	delay( 10000 );
	char rec_buff[ 80 ];
	memset( rec_buff, 0, sizeof(rec_buff) );
    int32_t type;
	int index = messip_receive( ch1, &type, rec_buff, sizeof(rec_buff), MESSIP_NOTIMEOUT );
	if ( index == -1 )
	{
		fprintf( stderr, "Error on receive message on channel '%s'\n", "one" );
		return -1;
	}
	display( "received %d-%d:'%s' type=%d from id=%s index=%d\n", 
		ch1->datalen, ch1->datalenr, rec_buff, type, ch1->remote_id, index );
	assert( !strcmp( rec_buff, "Hello" ) );
	assert( type == 1961 );
	display( "...waiting 10 seconds before replying to the client...\n" );
	delay( 10000 );
	messip_reply( ch1, index, 3005, "Bonjour", 8, MESSIP_NOTIMEOUT );

	/*--- Wait now channel-deconnexion message ---*/
	memset( rec_buff, 0, sizeof(rec_buff) );
	index = messip_receive( ch1, &type, rec_buff, sizeof(rec_buff), MESSIP_NOTIMEOUT );
	if ( index == -1 )
	{
		fprintf( stderr, "Error on receive message on channel '%s'\n", "one" );
		return -1;
	}
	display( "received %d-%d:'%s' type=%d from %s index=%d\n", 
		ch1->datalen, ch1->datalenr, rec_buff, type, ch1->remote_id, index );
	assert(index==MESSIP_MSG_DISCONNECT || index==MESSIP_MSG_DISMISSED);

	display( "End process\n" );
	return 0;
}                               // server
Exemplo n.º 6
0
Arquivo: p.c Projeto: osingla/messip
/**
 *  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