Aren’t you confortable with WebSockets and all enviroment behind it? Server configuration, providers, fallbacks and so on? Learning technologies like Signalr or Nodejs? And most of all, needs a fast development without those concerns?
First of All you need register on Pusher.com, this can be done with a Google account easily. Once you done your account you will have a dashboard view like image 01.
Just notice the Your apps Section on the left menu, there you will have information about your applications and create new ones, see image 02.
Now select the App Key menu to find the following informations:
- app_id: Provides an Id for that especific application
- key: a personal key
- secret: a personal secret.
See image 03.
And that is it… All the infrastructure is done, now we can start developing.
Visual Studio just loaded the basic templates for Asp.Net MVC 4 and we can add Pusher libraries using NUGET using the command “Install-Package PusherServer“, image 06.
On solution explorer, just add a controller and name it HomeController (Prety basic).
You will need at least these three namespaces.
- using PusherServer;
- using System.Web.Mvc;
- using System.Net;
Notice that on document load event i just subscribe to a channel named test_channel and add a listener to my_event event, so everything that triggers through the server will be listened in this html page as image 09 and image 10.
If you look at the image 07, you will notice that i just retrive from the url the key value and pass that to the trigger event that will be raised throught the listeners and react to that on image 08.
That is all you need to start smart and cool realtime apps, in the follow link you can download this example, but don’t forget to use your own Pusher account to that.
I hope you enjoy that fast and objective post.