tags:

views:

275

answers:

1

I work on a Comet application written in ASP.NET. There is an array of active connection contexts (HttpContext). And there is a thread that should periodically iterate through the collection and check theirs state. So application architecture is not thread-per-request.

What is the best way to check that a connection is active (not closed by the remote host)?

I found this:

context.Response.Write(' ');
context.Response.Flush();

if (!context.Response.IsClientConnected)
{
    // ...
}

But it's not a good solution because it takes a thread time to process (Flush() is blocking operation). I need solution that works very fast for many concurrent connections and don't use blocking operations.

Maybe there is some IIS or ASP.NET functionality that allows to monitor connections this way?

+1  A: 

The short answer is... no. The only way ASP.NET knows to return false for IsClientConnected is if the user makes a different call to the server, or Response.Close has been previously called. It's quite possible for the user to close the connection and still have IsClientConnected return true, in my experience. Just think about the underlying HTTP communication that's going on and you can see why.

What are you trying to accomplish?

Bryan
It's a chat service with Flash client-end. And this is the way to determine when a client goes offline.
alexey