Test Use Case: The Track Tool
To properly test something like FileMQ we need a test case that plays with live data. One of my sysadmin tasks is to manage the MP3 tracks on my music player. That is, by the way, a Sansa Clip reflashed with Rock Box, which I highly recommend. As I download tracks into my Music folder, I want to copy these to my player, and as I find tracks that annoy me, I delete them in the Music folder and want those gone from my player, too.
I could write this using a bash or Perl script—a powerful file distribution protocol is kind of overkill—but to be honest the hardest work in FileMQ was the directory comparison code, and I want to benefit from that. So I put together a simple tool called “track” that calls the FileMQ API. From the command line this runs with two arguments, the sending and receiving directories:
./track /home/ph/Music /media/3230-6364/MUSIC
The code is a neat example of how to use the FileMQ API to do local file distribution. Here is the full program, minus the license text (it’s MIT/X11 licensed):
#include "czmq.h"#include "../include/fmq.h"intmain(intargc,char*argv[]){fmq_server_t*server=fmq_server_new();fmq_server_configure(server,"anonymous.cfg");fmq_server_publish(server,argv[1],"/");fmq_server_set_anonymous(server,true);fmq_server_bind(server,"tcp://*:5670");fmq_client_t*client=fmq_client_new();fmq_client_connect(client,"tcp://localhost:5670");fmq_client_set_inbox(client,argv[2]);fmq_client_set_resync ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access