Kwwika ceased operation on 01/06/2011. Please migrate to Pusher

API‎ > ‎

C

C Library

You can get the Kwwika C Library on github:
Kwwika C Library

Getting Started

Connect

You can connect to the Kwwika service with a single call.

const char  *apiKey = "myAPIKey";
const char  *domain = "www.example.com";
kwwika  *client = kwwika_connect(apiKey, domain, NULL);

The third parameter represents a connection listener that is notified of changes in the status of the connection to the Kwwika service. In the case above we chosen not to supply a listener so our application won't be notified of changes in connection status.

Subscribe

Once you have connected to Kwwika you can subscribe to data. We use something called a topic to identify information. For instance our example chat application uses the /KWWIKA/EXAMPLES/CHAT topic. When you subscribe to a topic you also pass a listener that defines two methods. update is called when information becomes available for the topic you've subscribed to, and error is called if there is a problem with your subscription such as the topic does not exist within Kwwika.

// Define a subscription listener
static void topic_updated(kwwika *client, void *ctx, const char *topic, kwwika_fieldlist *fields, char isimage)
{
    printf("Topic Updated: %s\n",topic);
}

static void topic_error(kwwika *client, void *ctx, const char *topic, kwwika_topicerror error)
{
    printf("Topic Error: %s\n",topic);
}

static kwwika_topiclistener listener = {
    .update = topic_updated,
    .error = topic_error
};

// subscribe
kwwika_subscribe(client, "/KWWIKA/EXAMPLES/CHAT", &listener, NULL);

Publish

We've tried to keep publishing data as simple as possible. All you need to do is specify the topic you want to publish to, the names and values that you want to publish, and provide an listener that will be informed about whether your attempt to publish succeeded or not.

// create a command listener
static void command_ok(kwwika *client, void *ctx, const char *topic)
{
    printf("Publish successful for %s\n",topic);
}

static void command_error(kwwika *client, void *ctx, const char *topic, kwwika_topicerror error)
{
    printf("Publish failed for %s\n",topic);
}

static kwwika_commandlistener command_listener = {
    .ok = command_ok,
    .error = command_error
};

// Create a set of values to publish
kwwika_fieldlist *values = kwwika_fieldlist_new()
kwwika_fieldlist_add(values, "name", "Phil");
kwwika_fieldlist_add(values, "text", "Hello Kwwika!");

// Publish
kwwika_publish(client, "/KWWIKA/EXAMPLES/CHAT", values, &command_listener, NULL);

// And cleanup afterwards
kwwika_fieldlist_delete(values);