PokeIn Comet Ajax for .NET
Think about a library that you can easily access to server side objects from the client side or vice versa? I will explain how it's easy do this with PokeIn.
First, PokeIn is a free library and you can download it from here!
Let's create a simple application step by step. I will mention about the "
Bind" method to find our way.
public static bool Bind(string listenUrl, string sendUrl,
System.Web.UI.Page page, DefineClassObjects classDefs, out string ClientId);
Bind" provides the definition of server side objects on a client side. Also, with this method, the server side knows that there is a client connection request. "
Bind" defines an unique
ClientId for a client, creates the specified user classes and defines them on the client side. Shortly, if you add "
Bind" method to
CometAjax needed page, it will organize your page to communicate server side, i.e.:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
string ClientId = "";
i.e., you may define server side events for client side objects via PokeIn ;)
if (!PokeIn.Comet.CometWorker.Bind("Listen.aspx", "Send.aspx",
this, new PokeIn.Comet.DefineClassObjects(MyPage._Default.classDefiner),
MyPage._Default.classDefiner" ? It will create the objects that you defined per each client. So, every single object knows that the client belonged.
The code below is automatically generated by Visual Studio except the "
public partial class _Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
public static void classDefiner(string clientId, ref Dictionary<string> classList)
classList.Add("Dummy", new Dummy(clientId));
We defined our "
Dummy" class associated with the
clientId. Let me show
public class Dummy
public Dummy(string clientId)
ClientId = clientId;
public void Calculate(int x, int y)
"ResultCalculated(" + (x + y).ToString() + ");");
If your class needs the associated client information, you have a chance to hold it as I show in the example above. You will use
static PokeIn methods with this unique client id, i.e., in the above example, we called "
Here is the client side use of
Isn't that very easy? So, we sent "
ResultCalculated" from our server side method for "
Dummy.Calculate" call. Thus, client side will need this method definition. As you know, we called it "
ResultCalculated" but don't forget that you can send whatever you want.
The definition of "
function ResultCalculated( result )
alert( result );
Before we start our application, there are 2 definitions left. "Listen.aspx" and "Send.aspx" parameters in "
Bind" method? Names do not matter. Just add the lines below to define 2 different way handlers, i.e., Listen.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Listen.aspx.cs"
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Send.aspx.cs"
PokeIn uses the "
Listen" definition for server push operations and the "
Send" definition for client push operations.
Our comet Ajax based web application is completed! It's easier than DWR!
Using the Code
Download the code attached to this article to see how it works. You should download the library from here!
- Open the project.
- Right click to Project References.
- Add the "PokeIn.dll" you downloaded.
- 15th April, 2010: Initial post