#include #include #include #include #include #include "file_watch.h" // server IP #define IP_STR "193.188.34.81" // server PORT #define SERVER_PORT 6010 // filename that will be watched #define FILENAME "/home/tom/a.txt" // forward definition void fw_handler(watch_t file_watch, int event); main() { struct in_addr server_addr; inet_aton(IP_STR,&server_addr); int server_port = htons(SERVER_PORT); // details of watch watch_t my_watch; my_watch.ipaddress = server_addr; my_watch.port = server_port; my_watch.pathname = FILENAME; watch_t *watch_pt = &my_watch; // register watch int first_watch = register_distributed_watch( &watch_pt, 1, DELETION | MODIFICATION, fw_handler); // on error if (first_watch == -1) { printf("Things went bad!\n"); exit(-1); } // wait and then remove watch sleep(60); distributed_unwatch(first_watch); } // file watch handler code void fw_handler(watch_t file_watch, int event) { if (event == DELETION) { printf("%s has been deleted \n",FILENAME); } else if (event == MODIFICATION) { printf("%s has been modified \n",FILENAME); } else { printf("Ouch, dunno what happened !\n"); } }