1 #include "../src/logger.h"
2 #include "../src/system.h"
3 #include "../src/meshlink.h"
5 void handle_recv_data(meshlink_handle_t *mesh, meshlink_node_t *source, void *data, size_t len) {
6 printf("Received %zu bytes from %s: %s\n", len, source->name, (char*)data);
9 int main(int argc , char **argv){
10 char *confbase = argc > 1 ? argv[1] : "/tmp/meshlink/";
11 char *name = argc > 2 ? argv[2] : "foo";
13 char *remotename = argc > 3 ? argv[3] : "bar";
15 meshlink_handle_t* myhandle;
17 myhandle = meshlink_open(confbase, name);
19 //Register callback function for incoming data
20 meshlink_set_receive_cb(myhandle, (meshlink_receive_cb_t)handle_recv_data);
22 meshlink_start(myhandle);
27 meshlink_node_t *remotenode = meshlink_get_node(myhandle, remotename);
29 fprintf(stderr, "Node %s not known yet.\n", remotename);
33 //sample data to send out
36 strcpy(mydata,"Hello World!");
39 meshlink_send(myhandle,remotenode,mydata,sizeof(mydata));
42 meshlink_stop(myhandle);
43 meshlink_close(myhandle);