Example #1
0
        static public void Main()
        {
            // Init Pubnub Class
            pubnub objPubnub = new pubnub(
                "demo",  // PUBLISH_KEY
                "demo",  // SUBSCRIBE_KEY
                "demo",  // SECRET_KEY
                "demo",  //CIPHER_KEY
                false    // SSL_ON?
                );
            string channel = "test_channel";

            // History
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("channel", channel);
            args.Add("limit", 3.ToString());
            List <object> history = objPubnub.History(args);

            foreach (object history_message in history)
            {
                Console.Write("History Message: ");
                Console.WriteLine(history_message);
            }

            // Get PubNub Server Time
            object timestamp = objPubnub.Time();

            Console.WriteLine("Server Time: " + timestamp.ToString());
            Console.ReadKey();
        }
Example #2
0
        static public void Main()
        {
            // Init Pubnub Class
            pubnub objPubnub = new pubnub(
                "demo",  // PUBLISH_KEY
                "demo",  // SUBSCRIBE_KEY
                "demo",  // SECRET_KEY
                "demo",  // CIPHER_KEY
                false    // SSL_ON?
                );

            string channel = "test_channel";

            // Publish String Message
            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("channel", channel);
            args.Add("message", "Hello Csharp - mono");
            List <object> info = null;

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

            // Publish Message in array format
            args = new Dictionary <string, object>();
            object[] objArr = new object[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);
            Console.WriteLine("[" + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]");

            // Publish Message in Dictionary format
            args = new Dictionary <string, object>();
            Dictionary <string, object> objDict = new Dictionary <string, object>();
            Dictionary <string, object> val1    = new Dictionary <string, object>();

            objDict.Add("Student", "Male");
            val1.Add("Name", "Jhon");
            val1.Add("Age", "25");
            objDict.Add("Info", val1);

            args.Add("channel", channel);
            args.Add("message", objDict);

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

            Console.ReadKey();
        }
Example #3
0
        static public void test_subscribe()
        {
            // Initialize pubnub state
            pubnub objPubnub = new pubnub(
                "demo",  // PUBLISH_KEY
                "demo",  // SUBSCRIBE_KEY
                "demo",  // SECRET_KEY
                "",      // CIPHER_KEY   (Cipher key is Optional)
                false    // SSL_ON?
                );

            //define channel
            string channel = "hello-world";

            //Subscribe messages
            pubnub.Procedure Receiver = delegate(object message)
            {
                Console.WriteLine("Message - " + message);
                return(true);
            };
            pubnub.Procedure ConnectCallback = delegate(object message)
            {
                Console.WriteLine(message);
                return(true);
            };
            pubnub.Procedure DisconnectCallback = delegate(object message)
            {
                Console.WriteLine(message);
                return(true);
            };
            pubnub.Procedure ReconnectCallback = delegate(object message)
            {
                Console.WriteLine(message);
                return(true);
            };
            pubnub.Procedure ErrorCallback = delegate(object message)
            {
                Console.WriteLine(message);
                return(true);
            };

            Dictionary <string, object> args = new Dictionary <string, object>();

            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);

            Console.ReadKey();
        }
Example #4
0
        static public void Main()
        {
            //Initialize pubnub state
            pubnub objPubnub = new pubnub(
                "demo", // PUBLISH_KEY
                "demo", // SUBSCRIBE_KEY
                "demo", // SECRET_KEY
                "",     // CIPHER_KEY   [Cipher key is Optional]
                false   // SSL_ON?
                );

            Console.WriteLine("UUID - " + objPubnub.UUID());
            Console.ReadKey();
        }
Example #5
0
        static public void Main()
        {
            // Init Pubnub Class
            pubnub objPubnub = new pubnub(
                "demo",  // PUBLISH_KEY
                "demo",  // SUBSCRIBE_KEY
                "demo",  // SECRET_KEY
                "demo",  // CIPHER_KEY
                false    // SSL_ON?
                );
            string channel = "test_channel";

            Console.WriteLine("UUID - " + objPubnub.UUID());
            Console.ReadKey();
        }
Example #6
0
        static public void Main()
        {
            //Initialize pubnub state
            pubnub objPubnub = new pubnub(
                "demo",  // PUBLISH_KEY
                "demo",  // SUBSCRIBE_KEY
                "demo",  // SECRET_KEY
                "",      // CIPHER_KEY   (Cipher key is Optional)
                false    // SSL_ON?
                );
            // Get PubNub Server Time
            object timestamp = objPubnub.Time();

            Console.WriteLine("\nServer Time: " + timestamp.ToString());
            Console.ReadKey();
        }
Example #7
0
        static public void test_uuid()
        {
            // Initialize pubnub state
            pubnub objPubnub = new pubnub(
                "demo",  // PUBLISH_KEY
                "demo",  // SUBSCRIBE_KEY
                "demo",  // SECRET_KEY
                "",      // CIPHER_KEY   (Cipher key is Optional)
                false    // SSL_ON?
                );

            //Get UUID
            string uuid = objPubnub.UUID();

            Console.WriteLine("UUID - " + uuid);
        }
Example #8
0
        static public void Main()
        {
            // Init Pubnub Class
            pubnub objPubnub = new pubnub(
                "demo",  // PUBLISH_KEY
                "demo",  // SUBSCRIBE_KEY
                "demo",  // SECRET_KEY
                "demo",  // CIPHER_KEY
                false    // SSL_ON?
                );
            string channel = "test_channel";

            // Subscribe to the channel
            objPubnub.Subscribe(
                channel,
                delegate(object message)
            {
                Console.WriteLine("Message - " + message);
                return(true);
            }
                );
        }
Example #9
0
        static void UnitTestAll(pubnub pubnub)
        {
            if (runthroughs >= 2)
            {
                runthroughs = 0;
            }
            status.Clear();
            threads.Clear();

            _pubnub = pubnub;
            if (many_channels.Count <= 0)
            {
                for (int i = 0; i < many_channels.Capacity; i++)
                {
                    many_channels.Add("channel_" + i);
                }
            }
            status.Add("sent", 0);
            status.Add("received", 0);
            status.Add("connections", 0);

            foreach (string _channel in many_channels)
            {
                ParameterizedThreadStart pts = new ParameterizedThreadStart(run);
                Thread t = new Thread(pts);
                t.Start(_channel);
                threads.Add(_channel, t);
                try
                {
                    Thread.Sleep(500);
                }
                catch (ThreadInterruptedException e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            Console.ReadKey();
        }
Example #10
0
        static public void test_publish()
        {
            // Initialize pubnub state
            pubnub objPubnub = new pubnub(
                "demo",  // PUBLISH_KEY
                "demo",  // SUBSCRIBE_KEY
                "demo",  // SECRET_KEY
                "",      // CIPHER_KEY   (Cipher key is Optional)
                false    // SSL_ON?
                );

            //define channel
            string channel = "hello-world";

            // Publish string message
            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("channel", channel);
            args.Add("message", "Hello Csharp - mono");
            List <object> info = null;

            info = objPubnub.Publish(args);
            if (info != null)
            {
                if (info.Count == 3) //success
                {
                    Console.WriteLine("[ " + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]");
                }
                else if (info.Count == 2) //error
                {
                    Console.WriteLine("[" + info[0].ToString() + ", " + info[1] + "]");
                }
            }
            else
            {
                Console.WriteLine("Error in network connection");
            }
        }
Example #11
0
        static public void Main()
        {
            // Initialize pubnub state
            pubnub objPubnub = new pubnub(
                "demo",  // PUBLISH_KEY
                "demo",  // SUBSCRIBE_KEY
                "demo",  // SECRET_KEY
                "",      // CIPHER_KEY   (Cipher key is Optional)
                false    // SSL_ON?
                );

            //define channel
            string channel = "hello-world";

            // Publish string message
            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("channel", channel);
            args.Add("message", "Hello Csharp - mono");
            List <object> info = null;

            info = objPubnub.Publish(args);
            if (info != null)
            {
                if (info.Count == 3) //success
                {
                    Console.WriteLine("[ " + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]");
                }
                else if (info.Count == 2) //error
                {
                    Console.WriteLine("[" + info[0].ToString() + ", " + info[1] + "]");
                }
            }
            else
            {
                Console.WriteLine("Error in network connection");
            }

            // Publish message in array format
            args = new Dictionary <string, object>();
            object[] objArr = new object[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);

            // publish Response
            info = objPubnub.Publish(args);
            if (info != null)
            {
                if (info.Count == 3)
                {
                    Console.WriteLine("[" + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]");
                }
                else if (info.Count == 2)
                {
                    Console.WriteLine("[" + info[0].ToString() + ", " + info[1] + "]");
                }
            }
            else
            {
                Console.WriteLine("Error in network connection");
            }

            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);
            if (info != null)
            {
                if (info.Count == 3)
                {
                    Console.WriteLine("[" + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]");
                }
                else if (info.Count == 2)
                {
                    Console.WriteLine("[" + info[0].ToString() + ", " + info[1] + "]");
                }
            }
            else
            {
                Console.WriteLine("Error in network connection");
            }

            // History
            Dictionary <string, string> argsHist = new Dictionary <string, string>();

            argsHist.Add("channel", channel);
            argsHist.Add("limit", 3.ToString());
            List <object> history = objPubnub.History(argsHist);

            Console.Write("History Messages: ");
            foreach (object history_message in history)
            {
                Console.WriteLine(history_message);
            }

            //Get UUID
            string uuid = objPubnub.UUID();

            Console.WriteLine("UUID - " + uuid);

            // Get PubNub Server Time
            object timestamp = objPubnub.Time();

            Console.WriteLine("\nServer Time: " + timestamp.ToString());

            //Subscribe messages
            pubnub.Procedure Receiver = delegate(object message)
            {
                Console.WriteLine("Message - " + message);
                return(true);
            };
            pubnub.Procedure ConnectCallback = delegate(object message)
            {
                Console.WriteLine(message);
                return(true);
            };
            pubnub.Procedure DisconnectCallback = delegate(object message)
            {
                Console.WriteLine(message);
                return(true);
            };
            pubnub.Procedure ReconnectCallback = delegate(object message)
            {
                Console.WriteLine(message);
                return(true);
            };
            pubnub.Procedure ErrorCallback = delegate(object message)
            {
                Console.WriteLine(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);

            Console.ReadKey();
        }
Example #12
0
        static public void Main()
        {
            //Initialize pubnub state
            pubnub objPubnub = new pubnub(
                "demo", // PUBLISH_KEY
                "demo", // SUBSCRIBE_KEY
                "demo", // SECRET_KEY
                "",     // CIPHER_KEY  [Cipher key is Optional]
                false   // SSL_ON?
                );

            //channel name
            string channel = "hello-world";

            // Publish String Message
            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("channel", channel);
            args.Add("message", "Hello Csharp - mono");
            List <object> info = null;

            // publish Response
            info = objPubnub.Publish(args);
            if (info != null)
            {
                if (info.Count == 3) //success
                {
                    Console.WriteLine("[ " + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]");
                }
                else if (info.Count == 2) //error
                {
                    Console.WriteLine("[" + info[0].ToString() + ", " + info[1] + "]");
                }
            }
            else
            {
                Console.WriteLine("Error in network connection");
            }

            // Publish Message in array format
            args = new Dictionary <string, object>();
            object[] objArr = new object[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);

            // publish Response
            info = objPubnub.Publish(args);
            if (info != null)
            {
                if (info.Count == 3) //success
                {
                    Console.WriteLine("[" + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]");
                }
                else if (info.Count == 2) //error
                {
                    Console.WriteLine("[" + info[0].ToString() + ", " + info[1] + "]");
                }
            }
            else
            {
                Console.WriteLine("Error in network connection");
            }

            // Publish message in Dictionary format
            args = new Dictionary <string, object>();
            Dictionary <string, object> objDict = new Dictionary <string, object>();
            Dictionary <string, object> val1    = new Dictionary <string, object>();

            objDict.Add("Student", "Male");
            val1.Add("Name", "Jhon");
            val1.Add("Age", "25");
            objDict.Add("Info", val1);

            args.Add("channel", channel);
            args.Add("message", objDict);

            // publish Response
            info = objPubnub.Publish(args);
            if (info != null)
            {
                if (info.Count == 3) //success
                {
                    Console.WriteLine("[" + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]");
                }
                else if (info.Count == 2) //error
                {
                    Console.WriteLine("[" + info[0].ToString() + ", " + info[1] + "]");
                }
            }
            else
            {
                Console.WriteLine("Error in network connection");
            }

            Console.ReadKey();
        }
Example #13
0
        static public void Main()
        {
            // Init Pubnub Class
            pubnub objPubnub = new pubnub(
                "demo",  // PUBLISH_KEY
                "demo",  // SUBSCRIBE_KEY
                "demo",  // SECRET_KEY
                "demo",  //CIPHER_KEY
                false    // SSL_ON?
                );

            // define channel
            string channel = "test_channel";

            // Publish String Message
            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("channel", channel);
            args.Add("message", "Hello Csharp - mono");
            List <object> info = null;

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

            // Publish Message in array format
            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);
            Console.WriteLine("[" + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]");

            args = new Dictionary <string, object>();
            Dictionary <string, object> objDict = new Dictionary <string, object>();

            objDict.Add("Name", "Jhon");
            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] + "]");

            // History
            Dictionary <string, string> argsHist = new Dictionary <string, string>();

            argsHist.Add("channel", channel);
            argsHist.Add("limit", 3.ToString());
            List <object> history = objPubnub.History(argsHist);

            foreach (object history_message in history)
            {
                Console.Write("History Message: ");
                Console.WriteLine(history_message);
            }

            // Get UUID
            string uuid = objPubnub.UUID();

            Console.WriteLine("UUID - " + uuid);

            // Get PubNub Server Time
            object timestamp = objPubnub.Time();

            Console.WriteLine("\nServer Time: " + timestamp.ToString());

            // Subscribe messages
            objPubnub.Subscribe(
                channel,
                delegate(object message)
            {
                Console.WriteLine("\nMessage - " + message);
                return(true);
            }
                );

            Console.ReadKey();
        }