Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 9853843534

Fetching latest commit…

Cannot retrieve the latest commit at this time

..
Failed to load latest commit information.
examples
resource
src
README

README

## ---------------------------------------------------
##
## YOU MUST HAVE A PUBNUB ACCOUNT TO USE THE API.
## http://www.pubnub.com/account
##
## ----------------------------------------------------

## -------------------------------------------------
## PubNub 3.1 Real-time Cloud Push API - C#-IIS
## -------------------------------------------------
##
## PubNub is a Massively Scalable Real-time Service for Web and Mobile Games.
## This is a cloud-based service for broadcasting Real-time messages
## to thousands of web and mobile clients simultaneously.

## This tutorial is based on .Net Framework 4.0 (Visual Studio 2010)
## and this application is tested on IIS 7.

===============================================================================
TUTORIAL: HOW TO USE
===============================================================================

## Create a new web application

## Add reference of Newtonsoft.Json.dll from applications root\resource directory. 

## To use this API include Pubnub.cs, PubnubCrypto.cs files from applications root\src
## directory to your project and use functions from there as follows.

##  --------------------------------------------------------------------------------
##  C#-IIS : (Init)
##  ---------------

        //set the channel
        string channel = "hello-world";

        // Initialize pubnub state
        pubnub objPubnub = new pubnub(
            "demo",  // PUBLISH_KEY
            "demo",  // SUBSCRIBE_KEY
            "demo",  // SECRET_KEY
            "demo",  // CIPHER_KEY
            false    // SSL_ON?
            );
            
##  --------------------------------------------------------------------------------
##  C#-IIS : (Publish)
##  ------------------

        List<object> info = null;
        Dictionary<string, object> args = new Dictionary<string, object>();
        // Publish string  message
        args.Add("channel", channel);
        args.Add("message", "Hello Csharp - IIS");
        info = objPubnub.Publish(args);
        // Print response
        System.Diagnostics.Debug.WriteLine("Published messages - >");
        System.Diagnostics.Debug.WriteLine("[ " + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]");

        // Publish message in array format
        args = new Dictionary<string, object>();
        JArray jarr = new JArray();
        jarr.Add("Sunday");
        jarr.Add("Monday");
        jarr.Add("Tuesday");
        jarr.Add("Wednesday");
        jarr.Add("Thursday");
        jarr.Add("Friday");
        jarr.Add("Saturday");
        
        args.Add("channel", channel);
        args.Add("message", jarr);
        info = objPubnub.Publish(args);
        // Print response
        System.Diagnostics.Debug.WriteLine("[ " + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]");

        // Publish message in object (key - val) format
        args = new Dictionary<string, object>();
        JObject jObj = new JObject();
        jObj.Add("Name", "Jhon");
        jObj.Add("age", "25");

        args.Add("channel", channel);
        args.Add("message", jObj);
        info = objPubnub.Publish(args);
        // Print response
        System.Diagnostics.Debug.WriteLine("[" + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]");            
##  ------------------------------------------------------------------------------------
##  C#-IIS : (Subscribe)
##  --------------------
        // Subscribe to channel
        pubnub.Procedure callback = delegate(object message)
        {
            System.Diagnostics.Debug.WriteLine(" Message - > " +message);
            return true;
        };

        Dictionary<string, object> args = new Dictionary<string, object>();
        args.Add("channel", channel);
        args.Add("callback", callback);

        // Subscribe
        objPubnub.Subscribe(args);

##  --------------------------------------------------------------------------------
##  C#-IIS : (History)
##  ------------------
        //Get the history of messages 
        
        Dictionary<string, string> args = new Dictionary<string, string>();
        args.Add("channel", channel);
        args.Add("limit", 3.ToString());
        List<object> history = objPubnub.History(args);
        System.Diagnostics.Debug.WriteLine("History messages - > ");
        foreach (object history_message in history)
        {
            System.Diagnostics.Debug.WriteLine(history_message);
        }
        

##  --------------------------------------------------------------------------------
##  C#-IIS : (Time)
##  ---------------
        //Get the time
        System.Diagnostics.Debug.WriteLine("Server Time - > " + objPubnub.Time());
    
##  --------------------------------------------------------------------------------
##  C#-IIS : (UUID)
##  ---------------
        // Get UUID
        System.Diagnostics.Debug.WriteLine("Generated UUID - > " + objPubnub.UUID());

=====================================================================================
Something went wrong with that request. Please try again.