加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何找到一个asp.net客户端是immidiately断开连接

发布时间:2020-12-15 21:15:49 所属栏目:百科 来源:网络整理
导读:我知道Response.IsClientConnected但在我的场景中它有很大的滞后.码: // sample code for sending a dynamic file in chunckslong bytesSent = 0;while (continueSending) { if (!AskReceiverToContinue()) break; if (!Response.IsClientConnected) break;
我知道Response.IsClientConnected但在我的场景中它有很大的滞后.码:

// 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,buffer.Length);
         bytesSent += buffer.Length;
      }
      Catch
      {  // To my experience,this is more reliable than Response.IsClientConnected
         continueSending = false;
      }
   }

问题是客户端实际接收的字节数量远小于我的bytesSent.似乎当客户端断开连接时,我的程序发现了一个很大的滞后情况(并继续增加bytesSent),这是因为ASP.NET告诉我情况(客户端断开连接)很晚.

是否有任何可靠的方法可以找出客户端何时断开连接(实时)?

解决方法

你是通过HTTP转移的,不是吗?如果是,则由于HTTP协议的无状态而无法实现.您唯一需要帮助的是您已经使用的超时.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读