views:

231

answers:

5

In general chat application, client's browser always poll to server to check for new messages.

// the function to check new messages in server
function check(){

  // but this question is less about jQuery.
  $.ajax({
    type: "POST",
    url: "check.aspx",
    data: "someparam=123",
    success: function(msg){

       // process msg here

       // CHECK IT AGAIN, but sometimes we need to make delay here
       check();
    }
  });
}

Then I read Nicholas Allen's blog about Keeping Connections Open in IIS.

It makes me think if it is possible to push data from my server to client's browser by transfer chunked HTTP (it means like streaming, right?) and keep the connection open.

while keeping the connection open, in server, I have idea to keep something run to check new messages. something like this, maybe

while(connectionStillOpen) {
    // any new message?
    if( AnyMessage() )
    {
       // send chunked data, can I?
       SendMessageToBrowser();
       // may be we need to make delay here
       Sleep(forSomeTime);
    }
}

that's a raw idea.

My Chat App created in ASP.net. With my less understanding of WCF and advanced IIS streaming module, I need your advice about to implement this idea.

yea, Impossible is probably the answer. But I need to know why if its still impossible.

+3  A: 

Yes, it's impossible to push data from server directly to your browser client.

But you can to check server for new messages every, let's say, 3 seconds and refresh your client interface.

Maybe you want to take a look on some Comet implementations

Rubens Farias
a good resource. thanks.
Anwar Chandra
A: 

One method is there which is called Reverse AJAX. By using which server can transfer data to client without any request from the Client.

Devi
any link for that?
Anwar Chandra
The following code demonstrates it -http://www.codeproject.com/KB/custom-controls/CometMultiClient.aspx
Devi
A: 

The current generation of JavaScript / Ajax libraries don't provide access to partial responses; you only receive notification when the entire request is complete.

If you're open to using Silverlight, you can use a raw TCP connection.

Comet is another option -- but that's basically just long polling that still originates from client-side script.

RickNZ
+1  A: 

A server cannot initiate communication with the client. So the server cannot push data to the client. But you can achieve the push mechanism using "Reverse AJAX". The following article should shed more light.

Reverse AJAX

Hemanshu Bhojak
A: 

Its not possible to push the data from the server. Because HTTP respond only to the requests and cannot contact the client directly. But we have a workaround here called COMET or ReverseAJAX, by using this technique we can simulate the duplex calls.

Its nothing but the long living AJAX calls, and will respond to the client if there is a expected event happening in server side, otherwise it stays calm. This Comet (programming) wikipedia article explains more about the approach

I have answerd similar question here asp-net-chat-with-wcf. pls check out

Cheers

Ramesh Vel

Ramesh Vel