Introducing PubNub – the new cloud-hosted service for real-time messaging
PubNub is a new real-time cloud-based subscribe/publish API, it’s basically a hosted version of APE but we require no servers, minimal setup and a cross-platform API including JS, PHP and C# – perfect!
Let’s get stuck right in with some code examples. We’re going to re-create this post using PubNub but with a C# client, here’s the JavaScript:
Without going into too much detail, this example includes the PubNub API and subscribes to a channel. Messages are published when we select a colour from the drop down.
Here we have a simple C# console application that also subscribes to the same channel, listening for messages and changing the console background colour on request. Don’t forget to include the PubNub C# API when compiling.
static void Main(string[] args)
{
Pubnub pubnub = new Pubnub(
"demo",
"demo",
null,
false
);
List<0bject> history = pubnub.history("ifc0nfig", 1);
ChangeBackgroundColour(history.First());
pubnub.subscribe(
"ifc0nfig",
delegate(object message) {
ChangeBackgroundColour(message);
return true;
}
);
}
static void ChangeBackgroundColour(object message){
ConsoleColor cc = ConsoleColor.Black;
// we can't convert an RGB colour to a ConsoleColor so we'll have to set some manually mappings
if(message.ToString() == "#ffffff") cc = ConsoleColor.White;
if(message.ToString() == "#ff0000") cc = ConsoleColor.Red;
if(message.ToString() == "#00ff00") cc = ConsoleColor.Green;
if(message.ToString() == "#0000ff") cc = ConsoleColor.Blue;
Console.BackgroundColor = cc;
Console.Clear();
}
Go a head, launch the JavaScript client and the C# client – change the background colour and watch the magic happen:
Related posts:
- Using jQuery With APE
- EsenAPE – send and receive SMS in real time using APE, jQuery, PHP and libape_controller
- Diving into APE modules and the JSF – creating topics for channels
- Using jQuery with APE – an OOP approach with the DUI
- Keeping everything tidy within ASP.NET MVC3 C#; rendering your CSS and JavaScripts in the correct place



