Hello ØMQ

Sockets are not standardized in C++ world. So, when we want to use them, better to rely on some library that shield the low level platform dependent details. ASIO is a great choice, check yourself how to write a simple ASIO TCP client to have an idea of how it works.

Still, there are higher level alternatives, that makes our job even easier. One of them is provided by ØMQ (Zero Message Queue) a C library that is freely available for a number of operating system and programming languages.

They are working to release soon version 3.0, that is currently marked as unstable, I have downloaded it and played a bit around with it, but I assume is safer to use the stable release 2.1 instead.

I am writing this post while reading the Z-Guide. I suggest you to do the same. Actually, I would tell you to read it even if you are not much interested in the matter, because it is written in a very good and fun way.

Anyway. Here I just report about downloading, the stuff, setting up a VC++ project, and running a first 'hello' zmq application.

As I said, I am doing it on Windows, but on the page where you can get the software you can check how to build the library on *X systems, it looks very linear.

Not much to say either about creating a VC++ project, you should just remember to set the include and lib directories, specify a dependency to libzmq.lib, and make the libzmq.dll available to the executable.

What I am about to do with it, it is creating a powerful application that tells to the user which version of zmq is currently in use. OK, that is not much, but it is enough to test if everything is working as expected.

First thing, I should remember to include the zmq header file. Here I could have used zmq.h, that refers to the C code, but I use instead the C++ version, that wraps up the original include file to provide some friendly object-oriented support (here totally useless) to the code writer:
#include <iostream>
#include <zmq.hpp>

int main()
   int major, minor, patch;
   // zmq_version(&major, &minor, &patch); // pure C version
   zmq::version(&major, &minor, &patch); // C++ wrapper version
   std::cout << "Current 0MQ version is " << major << minor << patch << std::endl;
If this work, you should assume you have properly installed zmq in your environment.

No comments:

Post a Comment