Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 60793ec924

Fetching latest commit…

Cannot retrieve the latest commit at this time

..
Failed to load latest commit information.
src
HistoryExample.cs
Newtonsoft.Json.dll
PublishExample.cs
Pubnub.dll
PubnubCrypto.dll
PubnubTest.cs
README
SubscribeExample.cs
System.Runtime.Serialization.Json.dll
System.Runtime.Serialization.Json.xml
System.Web.Extensions.dll
System.Web.Extensions.xml
TimeExample.cs
UUIDExample.cs
UnsubscribeExample.cs
gmcs
mono-build
unit-test.cs

README

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

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

## -------------------------------------------
## ARE YOU COMPILING WITH .NET OLDER THAN 3.5?
## -------------------------------------------
## YOU MUST USE System.Web.Extensions.dll included in this directory.
## YOU MUST HAVE MONO ON YOUR MACHINE
##
## TO USE THIS FOLLOW THE STEPS IN 'mono-build', INCLUDED IN THIS DIRECTORY.

===============================================================================
PubNub C# Client API Boiler Plate
===============================================================================

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

    pubnub objPubnub = new pubnub(
		"demo",  // PUBLISH_KEY
		"demo",  // SUBSCRIBE_KEY
		"demo",  // SECRET_KEY
		"",      //CIPHER_KEY   (Cipher key is Optional)
		false    // SSL_ON?
    );
	
-------------------------------------------------------------------------------
C#: (Publish)
-------------------------------------------------------------------------------

	string channel = "test_channel"; // channel name
	
	// Publish String
    Dictionary<string, object> args = new Dictionary<string, object>();
	args.Add("channel", channel);
	args.Add("message", "Hello Csharp - mono");

	List<object> info = objPubnub.Publish(args);
	
	// Publish Response
    Console.WriteLine(info[0]); // 1
    Console.WriteLine(info[1]); // 'Demo' or "Error Message"
	Console.WriteLine(info[2]); // timetoken
	
	// Publish Array Of Messages
	args = new Dictionary<string, object>();
	string[] objArr = new string[7];

	objArr[0] = "Sunday";
	objArr[1] = "Monday";
	objArr[2] = "Tuesday";
	objArr[3] = "Wednesday";
	objArr[4] = "Thursday";
	objArr[5] = "Friday";
	objArr[6] = "Saturday";

	args.Add("channel", channel);
	args.Add("message", objArr);
	info = objPubnub.Publish(args);
	
	// Publish Response
	Console.WriteLine("[" + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]");
	
	// Publish Message In Object Format
	args = new Dictionary<string, object>();
	Dictionary<string, object> objDict = new Dictionary<string, object>();

	objDict.Add("Name", "John");            
	objDict.Add("Age", "25");

	args.Add("channel", channel);
	args.Add("message", objDict);
	info = objPubnub.Publish(args);
	Console.WriteLine("[" + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]");

	Console.ReadKey();

-------------------------------------------------------------------------------
C#: (Subscribe)
-------------------------------------------------------------------------------

	string channel = "test_channel"; // channel name
		
	pubnub.Procedure Receiver = delegate(object message)
	{
		Console.WriteLine("Message - " + message);
		return true;
	};
	pubnub.Procedure ConnectCallback = delegate(object message)
	{
		Console.WriteLine("Message - " + message);
		return true;
	};
	pubnub.Procedure DisconnectCallback = delegate(object message)
	{
		Console.WriteLine("Message - " + message);
		return true;
	};
	pubnub.Procedure ReconnectCallback = delegate(object message)
	{
		Console.WriteLine("Message - " + message);
		return true;
	};
	pubnub.Procedure ErrorCallback = delegate(object message)
	{
		Console.WriteLine("Message - " + message);
		return true;
	};
	
	args = new Dictionary<string, object>();	
	args.Add("channel", channel);
	args.Add("callback", Receiver);                 // callback to get response
	args.Add("connect_cb", ConnectCallback);        // callback to get connect event
	args.Add("disconnect_cb", DisconnectCallback);  // callback to get disconnect event
	args.Add("reconnect_cb", ReconnectCallback);    // callback to get reconnect event
	args.Add("error_cb", ErrorCallback);            // callback to get error event

	objPubnub.Subscribe(args);
	
-------------------------------------------------------------------------------
C#: (History)
-------------------------------------------------------------------------------

	string channel = "test_channel";
	
	// History	
	Dictionary<string, string> args = new Dictionary<string, string>();
	args.Add("channel", channel);
	args.Add("limit", 3.ToString()); //limit of messages to receive
	List<object> history = objPubnub.History(args);
	foreach (object history_message in history)
	{
		Console.Write("History Message: ");
		Console.WriteLine(history_message);
	}
	Console.ReadKey();
	
-------------------------------------------------------------------------------
C#: (Time)
-------------------------------------------------------------------------------	
    // Get PubNub Server Time
	object timestamp = objPubnub.Time();
	Console.WriteLine("Server Time: " + timestamp.ToString());
	
-------------------------------------------------------------------------------
C#: (UUID)
-------------------------------------------------------------------------------
	
	string channel = "test_channel"; // channel name
	
	// Print Unique identifier
	Console.WriteLine("UUID - " + objPubnub.UUID());
	Console.ReadKey();

-------------------------------------------------------------------------------
C#: (Unsubscribe)
-------------------------------------------------------------------------------
	// Unsubscribe to channel
	string channel = "test_channel"; // channel name
		
	pubnub.Procedure Receiver = delegate(object message)
	{
		Console.WriteLine("Message - " + message);
		Dictionary<string, object> arg = new Dictionary<string, object>();
        arg.Add("channel", channel);
        //Unsubscribe messages
        objPubnub.Unsubscribe(arg);
		return true;
	};
	pubnub.Procedure ConnectCallback = delegate(object message)
	{
		Console.WriteLine("Message - " + message);
		// Publish String Message
        Dictionary<string, object> publish = new Dictionary<string, object>();
        publish.Add("channel", channel);
        publish.Add("message", "Hello World!!!!"); 

        // publish Response
        objPubnub.Publish(publish);
		return true;
	};
	pubnub.Procedure DisconnectCallback = delegate(object message)
	{
		Console.WriteLine("Message - " + message);
		return true;
	};
	pubnub.Procedure ReconnectCallback = delegate(object message)
	{
		Console.WriteLine("Message - " + message);
		return true;
	};
	pubnub.Procedure ErrorCallback = delegate(object message)
	{
		Console.WriteLine("Message - " + message);
		return true;
	};
	
	args = new Dictionary<string, object>();	
	args.Add("channel", channel);
	args.Add("callback", Receiver);                 // callback to get response
	args.Add("connect_cb", ConnectCallback);        // callback to get connect event
	args.Add("disconnect_cb", DisconnectCallback);  // callback to get disconnect event
	args.Add("reconnect_cb", ReconnectCallback);    // callback to get reconnect event
	args.Add("error_cb", ErrorCallback);            // callback to get error event

	objPubnub.Subscribe(args);
	
Something went wrong with that request. Please try again.