Long Polling Comet in ASP.Net
What is Comet?
The original model of the web is one way communication. The web browser asks the server for some data and the server returns that data. The web browser can always tell the server when something happens but the server on the other hand can only respond back to the web browser. But sometimes you want the server to notify the web browser when an event occurs.A great example of this is your web email, when you go to your inbox you see all you new messages. But when a new email comes in you wouldn't know about it until you refreshed the inbox. But now if that site implemented Comet, you could see your emails popping in live. (btw GMail implements this)
So what is Long Polling Comet
A popular example of long polling usage is meebo.com and the main idea is to send a request to the server, the server then keeps that connection running until it either times out or an event occurs on the server. Once the event occurs, the details of that event is returned with that request. Once the web browser received the request, it makes another request and repeats this whole sequence.Since the request gets released from the server the moment the event occurs, that event reaches the web browser almost instantly, thus fast comet.
So how do I do it in ASP.Net?
The main thing to note about your implementation is that you can not hold on to all the threads that the requests comes in. Since we want to keep the Listen request for a very long time we want to make sure that its not hogging any resource. So make your Listen request an Async request (use IHttpAsyncHandler) and then on one or more of your own threads that control all the requests & releases them as necessary.Sample
The sample includes a working code of a chatroom. You can use \nick to change your nickname. (Warning: It's only meant to demonstrate the idea and is most likely faulty)Download Link
Hello,
The sample application does not function properly with IIS7 although it worked successfully with IIS6.
Did you test-it with IIS7?
Thank you in advance for your cooperation.
Houssam Hamdan on Wednesday 7th of July 2010 07:48:15 AM
Houssam Hamdan on Wednesday 7th of July 2010 07:48:15 AM