예제 #1
0
파일: Main.cs 프로젝트: aicl/Aicl.PubNub
        static public void Main()
        {
            //Initialize pubnub state
            PubChannel pubChannel = new PubChannel( new ChannelParams{
				PublishKey="demo",
				SubscribeKey="demo",
				SecretKey="demo"
			});

            //channel name
            string channel = "my_channel";

            // History
            
            List<object> history = pubChannel.History(new HistoryParams{
				ChannelName=channel,
				Limit=5
			});

			int i=0;
            foreach (object history_message in history)
            {
                Console.Write("History Message: ");
                Console.WriteLine(history_message);
				Console.WriteLine("---------------------  {0}  ----------", i++);
	
            }

            // Get PubNub Server Time
            object timestamp = pubChannel.Time();
            Console.WriteLine("Server Time: " + timestamp.ToString());
            
        }
예제 #2
0
파일: Main.cs 프로젝트: aicl/Aicl.PubNub
        static public void Main()
        {
            //Initialize pubnub state
            PubChannel pubChannel = new PubChannel( new ChannelParams{
				PublishKey="demo",
				SubscribeKey="demo",
				SecretKey="demo"
			});

            //channel name
            string channel = "my_channel";

			SubscribeParams sp = new SubscribeParams{
				ChannelName = channel,
				Receiver= o=>{
					Console.WriteLine("Incoming message:");
					Console.WriteLine(o);
					Console.WriteLine(o.GetType());
					return true;
				},
				ConnectCallback = o=>{
					Console.WriteLine("ConnectCallback:");
					Console.WriteLine(o);
                	return true;
				},
				DisConnectCallback = o=>{
					Console.WriteLine("DisConnectCallback:");
					Console.WriteLine(o);
                	return true;
				},
				ReConnectCallback = o=>{
					Console.WriteLine("ReConnectCallback:");
					Console.WriteLine(o);
                	return true;
				},
				ErrorCallback = o=>{
					Console.WriteLine("ErrorCallback:");
					Console.WriteLine(o);
                	return true;
				}

			};

			pubChannel.Subscribe(sp);

        }
예제 #3
0
파일: Main.cs 프로젝트: aicl/Aicl.PubNub
        static public void Main()
        {


			Console.WriteLine("HOla mundo");

			PubChannel pubnub = new PubChannel( new ChannelParams{
				PublishKey="demo",
				SubscribeKey="demo",
				SecretKey="demo"
			});

			string channel= "my_channel";

			List<object> info = null;
			info= pubnub.Publish(channel, "Hola Mundo soy Aicl.PubNub");
			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");
            }


			TestMessage tm = new TestMessage{
				Id= 10,
				Message ="hello aicl.pubnub New Publish",
				SomeBool =true,
				Date = DateTime.Today
			};


			info= pubnub.Publish<TestMessage>(channel, tm);
			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");
            }


			List<TestMessage> ltm = new List<TestMessage>();
			ltm.Add(tm);

			tm = new TestMessage{
				Id= 20,
				Message ="hello aicl.pubnub id = 20",
				Date = DateTime.Today.AddDays(10)
			};

			ltm.Add(tm);

			info= pubnub.Publish<TestMessage>(channel, ltm);
			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.WriteLine("This is The End");

        }