1.
集线器有disconnect这将允许您添加一个
回调函数,当断线发生:myHub.disconnect(function() {
alert('Server has disconnected');
});
如果你阿仁'枢纽然后为代码将帮助你:$(connection).bind("onDisconnect", function (e, data) {
callback.call(connection);
});
这显示了语法钩到底层连接的触发OnDisconnect事件。
2. 如果集线器那么IDisconnect接口。public class ChatHub : Hub, IDisconnect
{
public void Disconnect()
{
Debug.WriteLine(Context.ConnectionId + " disconnected");
}
}
对持续连接可以覆盖OnDisconnectAsync, (从SignalR维基于)public class MyEndPoint : PersistentConnection
{
protected override Task OnDisconnectAsync(string clientId)
{
return Connection.Broadcast("Client " + clientId + " disconncted");
}
}
3. 开始与SignalR v0.5.1它的工作原理是这样的:$.connection.hub.stateChanged(function (change) {
if (change.newState === $.signalR.connectionState.reconnecting) {
console.log("liveFeed is reconnecting!");
}
else if (change.newState === $.signalR.connectionState.connected) {
console.log("liveFeed is connected!");
}
});本回答被提问者采纳