2012-01-07 22 views
0

嗨,我有以下代碼:「網」拒絕發出「關閉」事件的NodeJS

this.stop = function() { 
    this.server.close(); 
    var thisServer = this; 
    this.server.on('close',function() { 
     thisServer.emit('stop');   
    });  
}; 

使用服務器和調用停止功能後,服務器拒絕 發出「關閉」事件

this.server.on('close',function() { 
     thisServer.emit('stop');   
    }); 

我做錯了什麼?

回答

1
this.server.on('close',function() { 
    thisServer.emit('stop');   
});  
this.server.close(); 
var thisServer = this; 

在調用close之前綁定關閉事件。

或者嘗試this.server.destroy();