【发布时间】:2014-07-20 12:32:11
【问题描述】:
有这样的骗局,但它们是针对库的先前版本的。好像代码变了。
我正在像这样实例化一个套接字:
this.socketLib || (this.socketLib = require('socket.io'));
this.socket = this.socketLib.listen(this.port);
在对象的其他地方,我有一个关闭函数。我尝试了以下方法来关闭套接字:
this.socket.close() # TypeError: Object #<Server> has no method 'close'
this.socket.server.close() # TypeError: Object #<Server> has no method 'close'
this.socket.server.disconnect() # TypeError: Cannot call method 'disconnect' of undefined
this.socket.disconnect() # TypeError: Object #<Server> has no method 'disconnect'
this.socket.io.engine.close() # TypeError: Cannot read property 'engine' of undefined
代码库中出现了disconnect,但它们似乎是针对客户端的:(link)。 close 基本上也是一样的。或者我没看到。
我已经调试并在对象中四处寻找,但没有发现任何关闭服务器的东西。
如何关闭新代码库中的套接字服务器?我需要关闭它以进行集成测试(第一次测试运行通过,第二次运行得到EADDRINUSE 错误)。我正在尝试编写一个可以在 mocha 中的 after 函数中运行的关闭函数。如果我在没有--watch 的情况下运行它们,我的测试就会通过。只是多次连续运行失败。
【问题讨论】:
-
看起来 1.0 仍然缺少以前版本的许多功能。
-
@dystroy 哎哟,不知道为什么?认为有更好的选择吗?
-
我不知道。现在我在等着看它在接下来的几天或几周内会如何变化。我冻结了我的应用程序中的迁移,直到它更清楚为止。
-
我刚刚降级到 0.9。我会为此提交一个问题。
-
作为问题提交(这应该由文档回答):github.com/Automattic/socket.io/issues/1559
标签: node.js websocket socket.io socket.io-1.0