当前位置: 首页>>代码示例>>C#>>正文


C# Pubnub.subscribe方法代码示例

本文整理汇总了C#中PubNub_Messaging.Pubnub.subscribe方法的典型用法代码示例。如果您正苦于以下问题:C# Pubnub.subscribe方法的具体用法?C# Pubnub.subscribe怎么用?C# Pubnub.subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PubNub_Messaging.Pubnub的用法示例。


在下文中一共展示了Pubnub.subscribe方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SubscribeDemo

        internal static void SubscribeDemo()
        {
            Pubnub pubnub = new Pubnub(
                        "demo",
                        "demo",
                        "",
                        "",
                        false);

            string channel = "my_channel";

            Console.WriteLine("Subscribe_Example");

            pubnub.subscribe(channel, DisplayReturnMessage);

            bool userexit = false;
            while (!userexit)
            {
                Console.WriteLine("For Unsubscribe");
                Console.WriteLine("Enter Y for UNSUBSCRIBE or ENTER X to EXIT subscribe loop");
                string userinput = Console.ReadLine();
                if (userinput.ToLower() == "y")
                {
                    pubnub.unsubscribe(channel, DisplayReturnMessage);
                    userexit = true;
                }
                else if (userinput.ToLower() == "x")
                {
                    userexit = true;
                }
            }
        }
开发者ID:netcon-source,项目名称:pubnub-api,代码行数:32,代码来源:Subscribe_Example.cs

示例2: Main

        public static void Main()
        {
            Pubnub pubnub = new Pubnub(
            "demo",
            "demo",
            "",
            false
            );
            string channel = "my/channel";
            string message = "Pubnub API Usage Example";

            pubnub.PropertyChanged += new PropertyChangedEventHandler(Pubnub_PropertyChanged);

            Console.WriteLine("UUID -> " + pubnub.generateGUID());

            pubnub.publish(channel, message);

            pubnub.history(channel, 10);

            pubnub.time();

            pubnub.subscribe(channel);

            Console.ReadKey();
        }
开发者ID:inncapsule,项目名称:CSharpUrlEncodingFix,代码行数:25,代码来源:Pubnub_Example.cs

示例3: ThenPresenceShouldReturnReceivedMessage

        public void ThenPresenceShouldReturnReceivedMessage()
        {
            receivedFlag1 = false;
            ThreadPool.QueueUserWorkItem((s) =>
                {
                    Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
                    string channel = "my/channel";

                    pubnub.presence<string>(channel, ThenPresenceShouldReturnMessage);

                    //since presence expects from stimulus from sub/unsub...
                    pubnub.subscribe<string>(channel, DummyMethodForSubscribe);
                    manualEvent1.WaitOne(2000);

                    pubnub.unsubscribe<string>(channel, DummyMethodForUnSubscribe);
                    manualEvent3.WaitOne(2000);

                    manualEvent2.WaitOne(310 * 1000);
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                       {
                           Assert.IsTrue(receivedFlag1, "Presence message not received");
                           TestComplete();
                       });
                });
        }
开发者ID:hart404,项目名称:pubnub-api,代码行数:25,代码来源:WhenAClientIsPresented.cs

示例4: SecureSubscribeDemo

        internal static void SecureSubscribeDemo()
        {
            Pubnub pubnub = new Pubnub(
                        "",
                        "demo",
                        "",
                        "pandu",
                        false);

            string channel = "my_channel";

            Console.WriteLine("Secure_Subscribe_Example");

            pubnub.subscribe(channel, DisplayReturnMessage);

            //Console.WriteLine("second channel");
            //pubnub.subscribe("second_channel", DisplaySubscribeReturnMessage1);

            //Console.WriteLine("third channel");
            //pubnub.subscribe("third_channel", DisplaySubscribeReturnMessage1);

            //Console.WriteLine("fourth channel");
            //pubnub.subscribe("fourth_channel", DisplaySubscribeReturnMessage1);

            //string channelNum = "";
            //do
            //{
            //    Console.WriteLine("For Unsub");
            //    Console.WriteLine("Enter 1 for my_channel, 2 for second_channel, 3 for third_channel, 4 for fourth channel, x for EXIT");
            //    channelNum = Console.ReadLine();
            //    if (channelNum == "1")
            //    {
            //        pubnub.unsubscribe(channel, DisplaySubscribeReturnMessage1);
            //    }
            //    else if (channelNum == "2")
            //    {
            //        pubnub.unsubscribe("second_channel", DisplaySubscribeReturnMessage1);
            //    }
            //    else if (channelNum == "3")
            //    {
            //        pubnub.unsubscribe("third_channel", DisplaySubscribeReturnMessage1);
            //    }
            //    else if (channelNum == "4")
            //    {
            //        pubnub.unsubscribe("fourth_channel", DisplaySubscribeReturnMessage1);
            //    }
            //} while (channelNum.ToLower() != "x");

            //Console.WriteLine("Please wait...");
            //Console.ReadLine();
        }
开发者ID:netcon-source,项目名称:pubnub-api,代码行数:51,代码来源:Subscribe_Example.cs

示例5: ThenSubscribeShouldReturnReceivedMessage

        public void ThenSubscribeShouldReturnReceivedMessage()
        {
            receivedMessage = false;
            Pubnub pubnub = new Pubnub("demo","demo","","",false);

            string channel = "test";

            EnqueueCallback(() => pubnub.subscribe<string>(channel, ReceivedMessageCallback));
            EnqueueCallback(() => pubnub.publish<string>(channel, "Test for WhenSubscribedToAChannel ThenItShouldReturnReceivedMessage", dummyPublishCallback));
            EnqueueConditional(() => isPublished);
            EnqueueConditional(() => isReceived);
            EnqueueCallback(() => Assert.IsTrue(receivedMessage, "WhenSubscribedToAChannel --> ThenItShouldReturnReceivedMessage Failed"));

            EnqueueTestComplete();
        }
开发者ID:hellogurus,项目名称:pubnub-api,代码行数:15,代码来源:WhenSubscribedToAChannel.cs

示例6: ThenItShouldReturnReceivedMessage

		public void ThenItShouldReturnReceivedMessage () 
		{
			
			Pubnub pubnub = new Pubnub (
				"demo",
				"demo",
				"",
				"",
				false);
			string channel = "hello_world";
			
			Common cm = new Common();
			cm.deliveryStatus = false;
			cm.objResponse = null;
			
			PubnubUnitTest unitTest = new PubnubUnitTest();
			unitTest.TestClassName = "WhenSubscribedToAChannel";
			unitTest.TestCaseName = "ThenSubscribeShouldReturnReceivedMessage";
			
			pubnub.PubnubUnitTest = unitTest;
			
			pubnub.subscribe (channel, cm.DisplayReturnMessage); 
			Thread.Sleep(3000);
			string msg = "Test Message";
			
			pubnub.publish (channel, msg, cm.DisplayReturnMessageDummy);
			//cm.deliveryStatus = false;
			while (!cm.deliveryStatus);
			if (cm.objResponse != null) {
				IList<object> fields = cm.objResponse as IList<object>;
				
				if (fields [0] != null)
				{
					var myObjectArray = (from item in fields select item as object).ToArray ();
					Console.WriteLine ("Resp:" + myObjectArray[0].ToString ());
					Assert.AreEqual(msg, myObjectArray[0].ToString());
				}
				else
				{
					Assert.Fail("No response");
				}
			}
			else
			{
				Assert.Fail("No response");
			}
		}
开发者ID:stjom,项目名称:pubnub-api,代码行数:47,代码来源:WhenSubscribedToAChannel.cs

示例7: ThenItShouldReturnReceivedMessage

        public void ThenItShouldReturnReceivedMessage()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "",
                false
            );
            string channel = "hello_world";
            Common cm = new Common();
            cm.deliveryStatus = false;
            cm.objResponse = null;

            PubnubUnitTest unitTest = new PubnubUnitTest();
            unitTest.TestClassName = "WhenAClientIsPresented";
            unitTest.TestCaseName = "ThenPresenceShouldReturnReceivedMessage";
            pubnub.PubnubUnitTest = unitTest;

            pubnub.presence(channel, cm.DisplayReturnMessage);
            //while (!cm.deliveryStatus) ;
            //cm.objResponse = null;
            pubnub.subscribe(channel, cm.DisplayReturnMessageDummy);
            while (!cm.deliveryStatus) ;

            string strResponse = "";
            if (cm.objResponse.Equals (null)) {
                Assert.Fail("Null response");
            }
            else
            {
                IList<object> fields = cm.objResponse as IList<object>;
                foreach (object item in fields)
                {
                    strResponse = item.ToString();
                    Console.WriteLine("Resp:" + strResponse);
                    //Assert.IsNotEmpty(strResponse);
                }
                Assert.AreEqual("hello_world", fields[2]);
            }
        }
开发者ID:stjom,项目名称:pubnub-api,代码行数:41,代码来源:WhenAClientIsPresented.cs

示例8: Subscribe_Example

        static void Subscribe_Example()
        {
            Pubnub pubnub = new Pubnub(
                    "demo",
                    "demo",
                    "",
                    false);
            string channel = "hello_world";

            pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "ReturnMessage")
                {
                    Console.WriteLine("\n********** Subscribe Messages ********** ");
                    MessageFeeder(((Pubnub)sender).ReturnMessage);
                }
            };
            pubnub.subscribe(channel);
        }
开发者ID:Vlanta,项目名称:c-sharp,代码行数:19,代码来源:Pubnub_Example.cs

示例9: Main

        static public void Main()
        {
            Console.WriteLine("HINT: TO TEST RE-CONNECT AND CATCH-UP,");
            Console.WriteLine("      DISCONNECT YOUR MACHINE FROM NETWORK/INTERNET AND ");
            Console.WriteLine("      RE-CONNECT YOUR MACHINE AFTER SOMETIME.");
            Console.WriteLine();
            Console.WriteLine("      IF NO NETWORK BEFORE MAX RE-TRY CONNECT,");
            Console.WriteLine("      NETWORK ERROR MESSAGE WILL BE SENT");
            Console.WriteLine();

            Console.WriteLine("ENTER Channel Name");
            channel = Console.ReadLine();

            Console.WriteLine(string.Format("Channel = {0}",channel));
            Console.WriteLine();

            Console.WriteLine("Enable SSL? ENTER Y for Yes, else N");
            string enableSSL = Console.ReadLine();
            if (enableSSL.Trim().ToLower() == "y")
            {
                Console.WriteLine("SSL Enabled");
            }
            else
            {
                Console.WriteLine("SSL NOT Enabled");
            }
            Console.WriteLine();

            Console.WriteLine("ENTER cipher key for encryption feature.");
            Console.WriteLine("If you don't want to avail at this time, press ENTER.");
            string cipheryKey = Console.ReadLine();
            if (cipheryKey.Trim().Length > 0)
            {
                Console.WriteLine("Cipher key provided.");
            }
            else
            {
                Console.WriteLine("No Cipher key provided");
            }
            Console.WriteLine();

            pubnub = new Pubnub("demo", "demo", "", cipheryKey,
                (enableSSL.Trim().ToLower() == "y") ? true : false);

            Console.WriteLine("ENTER 1 FOR Subscribe (not implementing connectCallback)");
            Console.WriteLine("ENTER 2 FOR Subscribe (implementing connectCallback)");
            Console.WriteLine("ENTER 3 FOR Publish");
            Console.WriteLine("ENTER 4 FOR Presence");
            Console.WriteLine("ENTER 5 FOR Detailed History");
            Console.WriteLine("ENTER 6 FOR Here_Now");
            Console.WriteLine("ENTER 7 FOR Unsubscribe");
            Console.WriteLine("ENTER 8 FOR Presence-Unsubscribe");
            Console.WriteLine("ENTER 9 FOR Time");
            Console.WriteLine("ENTER 0 FOR EXIT OR QUIT");

            bool exitFlag = false;

            Console.WriteLine("");
            while (!exitFlag)
            {
                string userinput = Console.ReadLine();
                switch (userinput)
                {
                    case "0":
                        exitFlag = true;
                        break;
                    case "1":
                        Console.WriteLine("Running subscribe() (not implementing connectCallback)");
                        pubnub.subscribe<string>(channel, DisplayReturnMessage);
                        //System.Threading.Tasks.Task subtask = System.Threading.Tasks.Task.Factory.StartNew(() => pubnub.subscribe<string>(channel, DisplayReturnMessage));
                        //pubnub.subscribe<object>(channel, DisplayReturnMessage);
                        //pubnub.subscribe(channel, DisplayReturnMessage);
                        break;
                    case "2":
                        Console.WriteLine("Running subscribe() (implementing connectCallback)");
                        pubnub.subscribe<string>(channel, DisplayReturnMessage, DisplayConnectStatusMessage);
                        //System.Threading.Tasks.Task subtask = System.Threading.Tasks.Task.Factory.StartNew(() => pubnub.subscribe<string>(channel, DisplayReturnMessage));
                        //pubnub.subscribe<object>(channel, DisplayReturnMessage);
                        //pubnub.subscribe(channel, DisplayReturnMessage);
                        break;
                    case "3":
                        Console.WriteLine("Running publish()");
                        Console.WriteLine("Enter the message for publish. To exit loop, enter QUIT");
                        string publishMsg = Console.ReadLine();
                        double doubleData;
                        int intData;
                        if (int.TryParse(publishMsg, out intData))
                        {
                            pubnub.publish<string>(channel, intData, DisplayReturnMessage);
                        }
                        else if (double.TryParse(publishMsg, out doubleData))
                        {
                            pubnub.publish<string>(channel, doubleData, DisplayReturnMessage);
                        }
                        else
                        {
                            //check whether any numeric is sent in double quotes
                            if (publishMsg.IndexOf("\"") == 0 && publishMsg.LastIndexOf("\"") == publishMsg.Length - 1)
                            {
                                string strMsg = publishMsg.Substring(1, publishMsg.Length - 2);
//.........这里部分代码省略.........
开发者ID:sevco777,项目名称:pubnub-api,代码行数:101,代码来源:Pubnub_Example.cs

示例10: Subscribe_Example

        public static void Subscribe_Example()
        {
            Pubnub pubnub = new Pubnub (
                   "demo",
                   "demo",
                   "",
                   "",
                   false);
            string channel = "hello_world";

            deliveryStatus = false;

            pubnub.subscribe (channel, DisplayReturnMessage);

            pubnub.publish (channel, "Test Message", DisplayReturnMessage);

            bool bStop = false;
            while (!bStop) {
                if (objResponse != null) {
                    IList<object> fields = objResponse as IList<object>;

                    if (fields [0] != null)
                    {
                         var myObjectArray = (from item in fields select item as object).ToArray ();
                        IEnumerable enumerable = myObjectArray [0] as IEnumerable;
                        if (enumerable != null) {
                            foreach (object element in enumerable)
                            {
                                Console.WriteLine ("Resp:" + element.ToString ());
                                bStop = true;
                            }
                        }
                    }
                }
            }
        }
开发者ID:netcon-source,项目名称:pubnub-api,代码行数:36,代码来源:PubNub-Example2.cs

示例11: Subscribe_Example

        static void Subscribe_Example()
        {
            Pubnub pubnub = new Pubnub(
                    "demo",
                    "demo",
                    "",
                    false);
            string channel = "my/channel";

            pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "ReturnMessage")
                {
                    Dictionary<string, object> _message = (Dictionary<string, object>)(((Pubnub)sender).ReturnMessage);
                    Console.WriteLine("Received Message -> '" + _message["text"] + "'");
                }
            };
            pubnub.subscribe(channel);
        }
开发者ID:inncapsule,项目名称:pubnub-api,代码行数:19,代码来源:Pubnub_Example.cs

示例12: StartListening

        public void StartListening()
        {
            _pubnub = new Pubnub(PUBLISH_KEY, SUBSCRIBE_KEY);
            _pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                    if (e.PropertyName=="ReturnMessage") {
                        Log.Debug("Got Message");
                        HandleMessage((Dictionary<string, object>)((Pubnub)sender).ReturnMessage);
                    }

            };
            _pubnub.subscribe(_channel);
        }
开发者ID:awlawl,项目名称:Maestro,代码行数:13,代码来源:PubnubMessaging.cs


注:本文中的PubNub_Messaging.Pubnub.subscribe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。