重新连接高速公路onclose事件

时间:2016-09-05 20:06:17

标签: node.js autobahn

我正在测试一些包含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()”行是否会阻止此事件自动发生?

1 个答案:

答案 0 :(得分:2)

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

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

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