Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用一个用 nodeJS 编写的自动化系统,它通过 nodeJS 的 ZMQ 绑定在云中创建连接它们的动态节点。有时我会收到错误Error: Address already in use,这是我的错,因为我在某处有一些错误。我想知道ZMQ的nodeJS绑定是否可以在绑定之前检查地址的可用性。
Error: Address already in use
这并不是我真正要寻找的,但最后我决定采用“简单”解决方案并使用try-catch块来检查绑定到host:port. 在实践中,这就是我所做的:
try-catch
host:port
try { receiver.bindSync("tcp://"+host+":" + port); } catch (e) { console.log(e); }
这是愚蠢而直接的。我正在寻找一种更准确的方法来执行此操作(例如,如问题中所述,一个检查地址可用性的功能,而不是捕获错误)。