如何确定服务器与SignalR客户端断开连接? [英] How to determine server disconnection from SignalR client?

查看:871
本文介绍了如何确定服务器与SignalR客户端断开连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是,SignalR JavaScript客户端如何在与服务器的连接丢失时检测到?

The question is how can SignalR JavaScript client detect when connection with server is lost?

感谢您的回复!

推荐答案

集线器具有方法disconnect,当断开连接时,该方法将允许您添加回调:

A hub has a method disconnect which will allow you to add a callback when disconnection takes place:

myHub.disconnect(function() {
  alert('Server has disconnected');
});

如果您不使用集线器,则断开连接方法的代码将为您提供帮助:

If you aren't using hubs then the code for the disconnect method will help you out:

$(connection).bind("onDisconnect", function (e, data) {
  callback.call(connection);
});

这显示了挂钩到基础连接的onDisconnect事件的语法.

This shows the syntax for hooking onto the onDisconnect event of the underlying connection.

这篇关于如何确定服务器与SignalR客户端断开连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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