有这样的骗局,但它们是针对该库的先前版本的。好像代码变了。
我正在像这样实例化一个套接字:
this.socketLib || (this.socketLib = require('socket.io'));
this.socket = this.socketLib.listen(this.port);
在对象的其他地方,我有一个 close 函数。我尝试了以下方法来关闭套接字:
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
,但它们似乎是针对客户端的:(链接)。同样的事情close
,基本上。或者我没看到。
我已经调试并在对象中四处寻找,但没有发现任何关闭服务器的东西。
如何关闭新代码库中的套接字服务器?我需要将其关闭以进行集成测试(第一次测试运行通过,第二次运行EADDRINUSE
出错)。我正在尝试编写一个可以after
在 mocha 函数中运行的关闭函数。如果我在没有--watch
. 只是多次连续运行失败。