RCFC

Remote C Function Call

by Pierre Mavrikios rcfc@petros.it 2010-09-01

 

Chat example

Permits chatting between many users connected to the net. The distributed application consists of two nodes :

While the top_chat program is running, a user in the network can join the chatting group, executing the program in a console terminal with its nick name as argument:
Whatever a user writes in its terminal, will be printed to the terminals of all users.


  1. Create the application's project directory tree.
Create the top directory "top_chat", somewhere in your file system.
Create the "term" directory under "top_chat".
Create the "rcfc_functions.def" file under the "term" directory.




  1. Declare the rcfc functions.
To create this rcfc application, just two remote functions have to be declared in the 'rcfc_functions.def' file.:

  1. Build the rcfc environment.
The "rcfcbuild" program, creates whatever is needed to develop of the rcfc  application.


Under every directory of the project tree:
will be created.




Project directory tree.

<

<
<
<
<

<
<
<




  1. Write the application source code.

Higher level
top_chat/rcfc_app.c
Lower level
top_chat/term/rcfc_app.c

Gets the user nick name from the command line argument.

    if ( argc != 2 )
    {
        printf ( "Error: User nick name is missing\n" );
        exit (-1);
    }
    nick = argv [1];

Initializes rcfc and grants the offered services (functions declared in "term/rcfc_functions.def")

    // init rcfc grant functions
    if ( !rcfc_grant_functions ( port, app_ide ) )
        exit ( -1 );

Initializes rcfc and offers the services to the "granter"(functions declared in "term/rcfc_functions.def")

    // init rcfc offer functions
    if ( !rcfc_offer_functions ( host, port, app_ide ) )
        exit ( -1 );


Wait until rcfc is ready.

    while ( !rcfc_is_offer_ready () );


Main application  loop while rcfc is alive ( kill it with CTRL C). The main loop does nothing. It just keeps the program running.

    while ( rcfc_is_grant_running () )
    {
        sleep ( 1 );
    }
Main application  loop while rcfc is alive ( kill it with CTRL C)


    while ( rcfc_is_offer_running () )
    {


Wait a message string from the terminal input.

        if ( fgets ( line, LINE_LEN, stdin ) != NULL )


Call the higher level remote function "rf_say" passing the nick name of the user and the inputed message string.

            if ( !rf_say ( nick, line ) )
                printf ( "Not responding\n" );

The "rf_say" function is executed, calling all lower level nodes function "rf_show" and returning the returned value.

int rf_say ( char *from, char *msg )
{
int ret;

    ret = rf_show ( from, msg );
    return ret;
}



The "rf_say" function is executed printing the formated string of the user's nick name and the sent message to the terminal, and returning "true" value.

int rf_show ( char *from, char *msg )
{
    printf ( "%s->%s", from, msg );
    return true;
}



  1. Build the distributed application.
To build the application programs, compile the source code and link it with the respective rcfc_libs and pthread library, for both levels.

"top_chat" directory.
"top_chat/term" directory.
gcc -Iinclude -o apu rcfc_app.c -Lrcfc -lrcfc_libs.x86_64 -lpthread
gcc -I../include -o apb rcfc_app.c -Lrcfc -lrcfc_libs.x86_64 -lpthread

Or run, under both directories, the "make" program.


  1. Application run.