Next: , Up: Writing a Client Library   [Contents]


4.3.2.1 Connecting to the Service

Before a client library can implement the application-specific protocol with the service, a connection must be created:

struct GNUNET_MQ_MessageHandlers handlers[] = {
    // ...
  GNUNET_MQ_handler_end ()
};
struct GNUNET_MQ_Handle *mq;

mq = GNUNET_CLIENT_connect (cfg,
                            "service-name",
                            handlers,
                            &error_cb,
                            NULL);

As a result a GNUNET\_MQ\_Handle is returned which can to used henceforth to transmit messages to the service. The complete MQ API can be found in gnunet\_mq\_lib.h. The hanlders array in the example above is incomplete. Here is where you will define which messages you expect to receive from the service, and which functions handle them. The error\_cb is a function that is to be called whenever there are errors communicating with the service.