C Client Open/Close Example
#include <stdio.h>
#include <stdlib.h>
/* JSM header */
#include "x_jsm.h"
#define JSMHOST "LOCALHOST:4560"
static char status[JSM_STATUS_SIZE+1];
static char response[JSM_RESPONSE_SIZE+1];
/* Main function */
int main(int argc, char **argv);
/* Utility functions */
void trim(char *str);
void printCharArray(char *chars, int size);
int main(int argc, char **argv)
{
char *host;
/* Get host from command line */
if (argc > 1)
{
host = argv[1];
}
else
{
host = JSMHOST;
}
/* Open JSM connection */
printf ( "\nJSMOPEN %s\n" , host );
JSMOPEN ( host , status , response );
trim ( response );
printf ( "status = %s\n" , status );
printf ( "response = %s\n\n" , response );
/* Check status */
if ( strncmp ( status , "OK" , 2 ) != 0 )
{
return 1;
}
/* Close JSM connection */
printf ( "JSMCLOSE\n" );
JSMCLOSE ( status , response );
trim ( response );
printf ( "status = %s\n" , status );
printf ( "response = %s\n\n" , response );
return 0;
}
void trim(char *str)
{
char *end = str;
while (*str)
if (*(str++) != ' ')
end = str;
*end = '\0';
}
void printCharArray(char *chars, int size)
{
int i;
putchar('"');
for (i=0; i<size; i++)
if (*chars)
putchar(*(chars++));
else
break;
putchar('"');
putchar('\n');
}