Install a Vagrant virtual machine.
The documentation of Vagrant is excellent. You can create a small Ubuntu VM to play with in just a few minutes. On OS X it installs from a standard .dmg / .pkg combination via the GUI.
Once you have your Vagrant installation, typing
vagrant init precise32 http://files.vagrantup.com/precise32.box
in a test directory initializes a new VM from a basic configuration provided by the Vagrant team.
vagrant up will boot your VM, and
vagrant ssh will SSH to your VM. Note that these commands need to be typed in the directory where your Vagrantfile (config file) is located.
(Also note that you need to have VirtualBox installed in order to operate your VMs. Vagrant scripts VirtualBox command-line tools in order to control its VMs.)
Build and install a current version of ZeroMQ.
ZeroMQ is easy to build from source. The install process is very typical. Download the tarball, unpack it, and then perform the usual invocation:
sudo make install
Compile the ZeroMQ test client and server
By default, the header files and zmq libraries are installed to /usr/local
cc hwclient.c -o hwclient -I/usr/local/include/ -lzmq -L/usr/local/lib/
cc hwserver.c -o hwserver -I/usr/local/include/ -lzmq -L/usr/local/lib/
For anything more complex than this a Makefile is recommended but these toy examples are so simple that it doesn’t matter in this case.
If you compile one of these within in the VM and one in your host OS, then you can communicate between VM and host OS via ZeroMQ.
Gotchas and things to remember
- need to run ‘ldconfig’ to configure new dynamically linked libraries after building ZeroMQ
- remember to include path to the header files and shared libraries in /usr/local (see above)
- don’t forget to pass the actual library to the linker via -lzmq
Running the server in a Vagrant VM, you can communicate between client and server across the virtual machine boundary. However, you will need to enable port forwarding in your Vagrantfile in order to make this possible. ZeroMQ defaults to port 5555, so forwarding 5555 in the guest OS to 5555 in the host OS makes this work transparently, as though it were operating within a single instance.
From this basic starting point, you can explore all sorts of interesting messaging configurations between “different” machines.