| 1 | = MobilityFirst Network Service API Design and Usage = |
| 2 | |
| 3 | == 1. Design == |
| 4 | |
| 5 | === 1.1 Basic Operations === |
| 6 | |
| 7 | === 1.2 Content Operations === |
| 8 | |
| 9 | === 1.3 Service Operations === |
| 10 | |
| 11 | == 2. Usage == |
| 12 | |
| 13 | === 2.1 Discussion === |
| 14 | |
| 15 | === 2.2 Examples === |
| 16 | |
| 17 | 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: |
| 18 | |
| 19 | {{{#!c |
| 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <mfapi.h> |
| 23 | |
| 24 | int main(int argc, char *argv[]) { |
| 25 | struct Handle handle; |
| 26 | //Choosing GUIDs 1 and 2 as reference |
| 27 | int mine = 1, other = 2, sent = 0, received = 0, size = 65*1024; |
| 28 | |
| 29 | //Buffer to send and receive messages; I don't care about the content |
| 30 | u_char buf[size]; |
| 31 | |
| 32 | //Requesting basic transport. Listening for GUID mine |
| 33 | ret = mfopen(&handle, "basic\0", NULL, mine); |
| 34 | if(ret) { |
| 35 | fprintf(stderr, "receiver: mfopen error\n"); |
| 36 | return (EXIT_FAILURE); |
| 37 | } |
| 38 | |
| 39 | //Send message to other. No additional services requested |
| 40 | sent = mfsend(&handle, buf, size, other, NULL); |
| 41 | if (sent < 0) { |
| 42 | fprintf (stderr,"mfsendmsg error\n"); |
| 43 | return EXIT_FAILURE; |
| 44 | } |
| 45 | |
| 46 | //Wait to receive new message |
| 47 | received = mfrecv_blk(&handle, buf, size, NULL, 0); |
| 48 | if (received < 0) { |
| 49 | fprintf (stderr,"mfrecv_blk error\n"); |
| 50 | return EXIT_FAILURE; |
| 51 | } |
| 52 | |
| 53 | printf("Intended to send %d bytes, sent %d bytes, received %d bytes\n", size, sent, received); |
| 54 | |
| 55 | mfclose(&handle); |
| 56 | return EXIT_SUCCESS; |
| 57 | } |
| 58 | }}} |