]> git.meshlink.io Git - meshlink/blob - examples/meshlinkapp.c
Move code from libmeshlink.c into the new functions in meshlink.c.
[meshlink] / examples / meshlinkapp.c
1 #include <system.h>
2 #include <meshlink.h>
3
4
5 void handle_recv_data(void *data);
6 void handle_recv_data(void *data) {
7 printf("Data received is %s\n",data);
8
9 }
10
11 int main(int argc , char **argv){
12 char *confbase = argc > 1 ? argv[1] : "/tmp/meshlink/";
13 char *name = argc > 2 ? argv[2] : "foo";
14 //debug_level = 5;
15
16 meshlink_node_t* remotenode = new_node();
17 char *remotename = argc > 3 ? argv[3] : "bar";
18
19 //TODO: change this, calling a function that returns node_t
20 //remotenode->name = malloc(16);
21 //remotenode->name = remotename;
22
23 meshlink_handle_t* myhandle;
24
25 meshlink_open(confbase, name);
26 meshlink_start(myhandle);
27
28 //Register callback function for incoming data
29 meshlink_receive_cb_t(handle_recv_data);
30
31 sleep(2); //there is a race condition here, tinc_start detaches to a thread the needs time to setup stuff
32 while(1) {
33
34 //sample data to send out
35 char mydata[200];
36 memset(mydata,0,200);
37 strcpy(mydata,"Hello World!");
38
39 //send out data
40 meshlink_send(myhandle,remotenode,mydata,sizeof(mydata));
41 sleep(10); //give time to this thread to finish before we exit
42 }
43 free(remotenode);
44 return 0;
45 }
46