【问题标题】:reconnect upon autobahn onclose event在高速公路 onclose 事件时重新连接
【发布时间】:2016-09-05 20:06:17
【问题描述】:

我正在测试一些高速公路代码,其中包括 onopen 事件和 onclose 事件。我注意到更新会停止,但是我的代码会继续运行,所以我怀疑连接丢失了。我将 onclose 事件更新为按以下方式存在:

connection.onclose = (reason, details) => {
  console.log("REASON", reason);
  console.log("DETAILS", details);
  reject(reason);
  process.exit();
};

当连接丢失时,我现在得到:

REASON lost
DETAILS { reason: null,
  message: null,
  retry_delay: 1.3305311206405022,
  retry_count: 1,
  will_retry: true }

我是否可以响应此事件并重新建立连接,或者我的“process.exit()”行是否会自动阻止这种情况发生?

【问题讨论】:

    标签: node.js autobahn


    【解决方案1】:

    Autobahn|JS 会自动重新连接(可配置 - 请参阅 http://autobahn.ws/js/reference.html#connection-options)。

    原则上,您也可以从关闭处理程序中再次调用连接的“打开”方法,例如如果你想要自定义重新连接逻辑。

    “onclose”处理程序中的关闭代码会关闭整个进程,因此不会尝试自动重新连接。

    【讨论】:

      猜你喜欢
      • 2017-06-04
      • 1970-01-01
      • 2017-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多