To get started you will want to create the Pubnub object
var pubnub = new Pubnub();
There are a number of optional parameters for new Pubnub(...), however the defaults will get you connected to the demo account that is live.
If you want to publish an event (or message) do the following, where "Your channel name" is a unique name for your channel. Please note that the object you publish must derive from Event.
public class MyEvent : Event { public int Foo { get; set; } public string Bar { get; set; } } pubnub.Channel("Your channel name").Publish(new MyEvent { Bar = "twelve", Foo = 12 });
And to subscribe to a particular event on a particular channel call Subscribe on the channel. In the example below I show two different ways to get called back, one via a lambda and other other via a method:
pubnub.Channel("Your channel name").Subscribe(m => Console.WriteLine(m.Bar)); pubnub.Channel("Your channel name").Subscribe(GotMessage); private static void GotMessage(MyEvent message) { Console.WriteLine(message.Bar + message.Foo); }
The sample in the source code tree covers these example scenarios.