PreCache NetInjector Documentation Center : PreCache NetInjector Application Development

Basic Case, Publication — C

   







Basic Case, Publication code — C

— the full code sample for publishing


The previous code samples presented the basics of publishing. A publication application initializes channels, proxies, subjects, and attributes for content distribution.

The basic sequence of the publication process in the completed application is:

  1. Create a proxy connection for the channel. ( Proxy Initialization)
  2. Create a notification for the subject; set the value of the predefined attribute. ( Notification)
  3. Publish the notification for the subject over the channel. ( Content publication)

#include <stdio.h>

#include "PC_utl_log.h"

#include "PC_evn_filter.h"

#include "PC_evn_proxy.h"

#include "PC_evn_notification.h"

int

main(int argc, char* argv[])

{

      PC_Status nStatus;

//Create a proxy for the channel and client.

      PC_evn_Proxy p;

      PC_evn_Notification n;

      nStatus = PC_evn_create_proxy(&p,7,3001);

      if (nStatus != PC_SUCCESS)      

      {

            printf("Proxy creation has failed\n");

            return 0;

      }

//Create a notification for the subject.

      nStatus = PC_evn_create_notification(
            &n, p,"Sample.Intro1",NULL);

      if (nStatus != PC_SUCCESS)      

      {

            printf("Notification creation has failed
                  \n");

            return 0;

      }

//Set the value of the predefined attribute.

      PC_evn_set_predefined_attr_by_name(n,
            "Message","Hello World",
            PC_STRING_TYPE,strlen("Hello World"));

//Publish the notification for the subject.

      nStatus = PC_evn_publish(p,n);

      if (nStatus != PC_SUCCESS)

      {

            printf("Failed to publish notification
                  \n");

            return 0;

      }

}

In the next chapter, Basic Case, Subscription — C, we will construct a simple application for retrieving the published message.