wiki:Proto/cModules/d0NetworkServiceAPI/a0DesignUsage
close Warning: Can't synchronize with repository "(default)" ("(default)" is not readable or not a Git repository.). Look in the Trac log for more information.

MobilityFirst Network Service API Design and Usage

1. Design

1.1 Basic Operations

1.2 Content Operations

1.3 Service Operations

2. Usage

2.1 Discussion

2.2 Examples

The following code snippet shows a simple C program written using the API that sends a message to another GUID identified endpoint and receives the corresponding response:

#include <stdio.h>
#include <stdlib.h>
#include <mfapi.h>

int main(int argc, char *argv[]) {
        struct Handle handle;
        //Choosing GUIDs 1 and 2 as reference
        int mine = 1, other = 2, sent = 0, received = 0, size = 65*1024;

        //Buffer to send and receive messages; I don't care about the content
        u_char buf[size];

        //Requesting basic transport. Listening for GUID mine
        ret = mfopen(&handle, "basic\0", NULL, mine);
        if(ret) {
                fprintf(stderr, "receiver: mfopen error\n");
                return (EXIT_FAILURE);
        }

        //Send message to other. No additional services requested
        sent = mfsend(&handle, buf, size, other, NULL);
        if (sent < 0) {
                fprintf (stderr,"mfsendmsg error\n");
                return EXIT_FAILURE;
        }

        //Wait to receive new message
        received = mfrecv_blk(&handle, buf, size, NULL, 0);
        if (received < 0) {
                fprintf (stderr,"mfrecv_blk error\n");
                return EXIT_FAILURE;
        }

        printf("Intended to send %d bytes, sent %d bytes, received %d bytes\n", size, sent, received);

        mfclose(&handle);
        return EXIT_SUCCESS;
}
Last modified 6 years ago Last modified on Nov 30, 2014, 5:14:09 AM
Note: See TracWiki for help on using the wiki.