与SignalR检测“服务器脱机” [英] Detect 'server offline' with SignalR

查看:205
本文介绍了与SignalR检测“服务器脱机”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正试图使用​​SignalR在低带宽环境下,到后端服务器的连接可以来去随意,我们希望我们的Web应用程序作出适当的反应。

We are attempting to use SignalR in an low-bandwidth environment where the connection to the backend server can come and go randomly, and we want our web application to respond appropriately.

它看起来像这样连接API一直在不断变化,过去的一年,但根据最新​​的文档,我试图挂钩高达$ .connection.hub.stateChanged检测连接状态的变化,我也得到一对夫妇打在启动时,客户端从断开的老话 - >连接 - >连接,但是当我停止服务器,事件处理程序不火,当我再次启动服务器,实时通讯不再工作。

It looks like this connection API has been in flux over the past year, but in accordance with the latest documentation, I have tried hooking up to $.connection.hub.stateChanged to detect changes in the connection status, and I get a couple hits on startup when the client goes from disconnected -> connecting -> connected, but when I stop the server, the event handler does not fire, and when I start the server again, the real-time messaging is no longer working.

要测试这种情况下,我在Windows 7上运行ASP.NET的Web服务器在IIS和Web客户端在谷歌浏览器上运行。一旦网站运行和消息被交换,我杀了IIS中的网站和消息停下,但客户没有收到任何通知。

To test this scenario, I am on Windows 7 running the ASP.NET web server in IIS and the web client is running in Google Chrome. Once the site is running, and messages are being exchanged, I kill the website in IIS, and the messages stop but the client does not receive any notification.

下面是一个简单的代码片段(使用打字稿):

Here's a quick snippet (using TypeScript):

$.connection.hub.stateChanged((change) => {
   console.log("state changed...");
   console.log(change);

   if (change.newState === $.signalR.connectionState.reconnecting) {
      this.raise('action:disconnected');
   }
   else if (change.newState === $.signalR.connectionState.connected) {
      this.raise('action:connected');
   }
});

任何指导将是非常美联社preciated,谢谢!

Any guidance would be much appreciated, thanks!

-Jeremy

推荐答案

什么版本SignalR您使用的是?在最新的(和个前)服务器脱机立即检测和状态变化提出的重新连接标志。

What version of SignalR are you using? In the latest (and ones before it) the server going offline is immediately detected and the state change is raised with the reconnecting flag.

要杀死服务器,我假设你的意思是关闭IIS .e.g IISRESET。在停止的INETMGR网站做的的关闭该网站了,它只是删除的Http.sys该端口绑定。请参见 https://github.com/SignalR/SignalR/issues/1148 了解更多信息

To kill the server, I assume you mean shut down IIS .e.g iisreset. Stopping the website in inetmgr does NOT shut the site down, it merely removes the Http.sys binding for that port. See https://github.com/SignalR/SignalR/issues/1148 for more info.

如果要模拟服务器下去杀W3WP。

If you want to simulate the server going down kill w3wp.

这篇关于与SignalR检测“服务器脱机”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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