immidiately是如何找到一个asp.net客户端断开连接 [英] How to find an asp.net client is disconnected immidiately

查看:273
本文介绍了immidiately是如何找到一个asp.net客户端断开连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 Response.IsClientConnected ,但在我的情况有很大的滞后性。 code:

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;
      }
   }

问题是由客户端实际接收的字节数在数量比我的 bytesSent 非常小。看来,当一个客户端断开连接我的程序找出一个伟大滞后的局面(并继续增加 bytesSent ),这是因为ASP.NET告诉我的情况(客户端断开连接)已晚。

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) ?

推荐答案

正在转流通过HTTP,不是吗?如果是的话,没有办法,由于HTTP协议的无状态性。只有你一定要帮你的事情是超时,你已经在使用。

You are transfering over HTTP, aren't you? If yes, there is no way due to the statelessness of the HTTP protocol. Only thing you have to help you is the timeout, which you are already using.

这篇关于immidiately是如何找到一个asp.net客户端断开连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆