'net'拒绝排放'关闭'nodejs中的事件

'net' refuses to emit 'close' event in nodejs

本文关键字:事件 nodejs net 拒绝 关闭      更新时间:2023-09-26

hi我有以下代码:

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');        
    }); 

我做错什么了吗?

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

在调用关闭之前绑定关闭事件。

或者尝试this.server.destroy();