I'm aware of Response.IsClientConnected
but in my scenario it has a great lag. Code:
// sample code for sending a dynamic file in chuncks
long bytesSent = 0;
while (continueSending)
{
if (!AskReceiverToContinue())
break;
if (!Response.IsClientConnected)
break;
// Your suggestion goes here... :)
try
{
Response.OutputStream.Write(buffer, 0, buffer.Length);
bytesSent += buffer.Length;
}
Catch
{ // To my experience, this is more reliable than Response.IsClientConnected
continueSending = false;
}
}
The problem is the actual received bytes by client is very smaller in amount than my bytesSent
. It seems when a client gets disconnected my program finds out the situation with a great lag (and continue increasing bytesSent
) and this is because ASP.NET tells me the situation (client is disconnected) late.
Is there any reliable method for finding out when a client has been disconnected (real-time) ?