Esempio n. 1
0
        static void Main()
        {
            // Start the HTML5 Pubnub client
            Process.Start("..\\..\\PubnubClient.html");

            System.Threading.Thread.Sleep(2000);

            PubnubAPI pubnub  = new PubnubAPI(PUBLISH_KEY, SUBSCRIBE_KEY, SECRET_KEY, true);
            string    channel = "chat-channel";

            // Publish a sample message to Pubnub
            List <object> publishResult = pubnub.Publish(channel, "Hello Pubnub!");

            Console.WriteLine(
                "Publish Success: " + publishResult[0].ToString() + "\n" +
                "Publish Info: " + publishResult[1]
                );

            // Show PubNub server time
            object serverTime = pubnub.Time();

            Console.WriteLine("Server Time: " + serverTime.ToString());

            // Subscribe for receiving messages (in a background task to avoid blocking)
            System.Threading.Tasks.Task t = new System.Threading.Tasks.Task(
                () =>
                pubnub.Subscribe(
                    channel,
                    delegate(object message)
            {
                Console.WriteLine("Received Message -> '" + message + "'");
                return(true);
            }
                    )
                );
            t.Start();

            // Read messages from the console and publish them to Pubnub
            while (true)
            {
                Console.Write("Enter a message to be sent to Pubnub: ");
                string msg = Console.ReadLine();
                pubnub.Publish(channel, msg);
                Console.WriteLine("Message {0} sent.\n", msg);
            }
        }
Esempio n. 2
0
        public static void Main()
        {
            Process.Start(Path.GetFullPath("../../PubNubClient.html"));

            Thread.Sleep(2000);

            PubnubAPI pubnub  = new PubnubAPI(PUBLISH_KEY, SUBSCRIBE_KEY, SECRET_KEY);
            string    channel = "chat-channel";

            List <object> publishResult = pubnub.Publish(channel, "Hi");

            Console.WriteLine("Publish success: " + publishResult[0] + "\n" +
                              "Publish Info: " + publishResult[1]);

            object serverTime = pubnub.Time();

            Console.WriteLine("Server time: " + DateTime.Parse(serverTime.ToString()));

            Task t = new Task(() => pubnub.Subscribe(
                                  channel,
                                  delegate(object message)
            {
                Console.WriteLine("Received message => " + "\"" + message + "\"");
                Console.WriteLine(new string('=', 60));
                Console.WriteLine();
                return(true);
            }));

            t.Start();

            if (t.Status == TaskStatus.Running)
            {
                Console.WriteLine("hi");
            }

            while (true)
            {
                Console.WriteLine("Enter a message: ");
                msg = Console.ReadLine();
                pubnub.Publish(channel, msg);
                Console.WriteLine("Message \"{0}\" sent.\n", msg);

                Thread.Sleep(1000);
            }
        }
        static void Main()
        {
            // Start the HTML5 Pubnub client
            Process.Start("..\\..\\PubnubClient.html");

            System.Threading.Thread.Sleep(2000);

            PubnubAPI pubnub = new PubnubAPI(PUBLISH_KEY, SUBSCRIBE_KEY, SECRET_KEY, true);
            string channel = "chat-channel";

            // Publish a sample message to Pubnub
            List<object> publishResult = pubnub.Publish(channel, "Hello Pubnub!");
            Console.WriteLine(
                "Publish Success: " + publishResult[0].ToString() + "\n" +
                "Publish Info: " + publishResult[1]
            );

            // Show PubNub server time
            object serverTime = pubnub.Time();
            Console.WriteLine("Server Time: " + serverTime.ToString());

            // Subscribe for receiving messages (in a background task to avoid blocking)
            System.Threading.Tasks.Task t = new System.Threading.Tasks.Task(
                () =>
                pubnub.Subscribe(
                    channel,
                    delegate (object message)
                    {
                        Console.WriteLine("Received Message -> '" + message + "'");
                        return true;
                    }
                )
            );
            t.Start();

            // Read messages from the console and publish them to Pubnub
            while (true)
            {
                Console.Write("Enter a message to be sent to Pubnub: ");
                string msg = Console.ReadLine();
                pubnub.Publish(channel, msg);
                Console.WriteLine("Message {0} sent.\n", msg);
            }
        }
        public static void Main()
        {
            Process.Start(Path.GetFullPath("../../PubNubClient.html"));

            Thread.Sleep(2000);

            PubnubAPI pubnub = new PubnubAPI(PUBLISH_KEY, SUBSCRIBE_KEY, SECRET_KEY);
            string channel = "chat-channel";

            List<object> publishResult = pubnub.Publish(channel, "Hi");
            Console.WriteLine("Publish success: " + publishResult[0] + "\n" +
                "Publish Info: " + publishResult[1]);

            object serverTime = pubnub.Time();
            Console.WriteLine("Server time: " + DateTime.Parse(serverTime.ToString()));

            Task t = new Task(() => pubnub.Subscribe(
                channel,
                delegate (object message)
                {
                    Console.WriteLine("Received message => " + "\"" + message + "\"");
                    Console.WriteLine(new string('=', 60));
                    Console.WriteLine();
                    return true;
                }));
            t.Start();

            if (t.Status == TaskStatus.Running)
            {
                Console.WriteLine("hi");
            }

            while (true)
            {
                Console.WriteLine("Enter a message: ");
                msg = Console.ReadLine();
                pubnub.Publish(channel, msg);
                Console.WriteLine("Message \"{0}\" sent.\n", msg);

                Thread.Sleep(1000);
            }
        }