Go to the first, previous, next, last section, table of contents.


FM example

#include <fm.h>

#define TRUE (1==1)
#define FALSE !TRUE // Basic Definitions
#define MAX_NODE 1 // Number of Nodes - 1

int Done;
int Hello;

char MsgBuffer[]="Hello World.\n"; // Message we're going to send

int HelloHandler(FM_stream *strm, unsigned int snd) {
        char GetBuffer[sizeof(MsgBuffer)]; // Buffer to receive into
        FM_receive(GetBuffer, strm, sizeof(GetBuffer)); // Receive network data
        Done=TRUE; // Ok. Once done receiving, tell the program to continue
        printf("Received: %s\n", GetBuffer);
        return FM_CONTINUE;
}

int main(int argc, char **Argv) {
        int i;
        FM_stream* Strm;

        FM_set_parameter(FM_KEY_NAME, Argv[1]); // Set our key name
        FM_initialize();

        Hello=FM_register_handler(FM_ANY_ID, HelloHandler); // Init and specify
        Done=0; // Handler.

        if(FM_nodeid==MAX_NODE) { // Sender
                for(i=0; i<FM_nodeid; i++) { // Begin the 'hello' send
                                        // Send to the 'Hello' handler,
                                        // the entire contents of MsgBuffer
                        Strm=FM_begin_message(i, sizeof(MsgBuffer), Hello);

                        // Send piece
                        FM_send_piece(Strm, MsgBuffer, sizeof(MsgBuffer));
                        // And end the message
                        FM_end_message(Strm);
                }
        } else {
                while(Done==FALSE)// While the handler hasnt set the 'Done' flag
                        FM_extract(~0); // 'extract' ~0 = MAXLONG bytes
        }

        FM_finalize(); // End the program
}


Go to the first, previous, next, last section, table of contents.