如何closuressocket.io 1.0中的服务器?

有一些这样的,但他们是以前版本的图书馆。 看来代码已经改变了。

我正在实例化一个套接字,如下所示:

this.socketLib || (this.socketLib = require('socket.io')); this.socket = this.socketLib.listen(this.port); 

在对象的其他地方,我有一个closuresfunction。 我试过以下closures套接字:

 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 ,但是它们对于客户端来说似乎是:( 链接 )。 基本上同样的事情。 或者我没有看到它。

我已经debugging并在对象周围戳,并没有发现任何closures服务器。

如何closures新代码库中的套接字服务器? 我需要closures集成testing(第一次testing运行通过,第二次运行得到EADDRINUSE错误)。 我想写一个closuresfunction,我可以在摩卡after我的afterfunction运行。 我的testing通过,如果我运行他们没有 – --watch 。 这只是连续多次失败。

希望能帮助到你 :-)

 socket.conn.close (); 

如果你这样做,你会得到无限数量的"a user connected"

 var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); io.on('connection', function(socket){ console.log('a user connected'); socket.conn.close (); .... });