Node.js - tcp server close event handler is not working -


why end event handler(socket) , close event handler(server) being called @ same time? expecting close event handler called after 30 seconds.

can please me?

although after 30 seconds tcp server not accepting new connection(keeps existing connections open) expecting close event handler invocation after 30 sec. close event handler of server end event handler of socket invoked when forcefully close existing tcp clients.

tcp connection ended
tcp connection ended
server closed keep existing connection

var net = require("net");  function getsocketinfo(socketobject){                     console.log('bytesread= ' + socketobject.bytesread);                     console.log('byteswritten= ' + socketobject.byteswritten); }  var tcpserver = net.createserver({allowhalfopen:false},function(socketobject){                 socketobject.setencoding('utf8');                 getsocketinfo(socketobject);                 socketobject.on('data',function(data){                         console.log('data received');                         console.log(data);                         console.log(data.length);                         socketobject.write('server reply: ' + data,'utf8',function(){                         console.log('data written on socket');                         });                         getsocketinfo(socketobject);                         });                  socketobject.on('end',function(){                         console.log('tcp connection ended');                         });                 });  settimeout(function(){tcpserver.close();},30000);  tcpserver.on('close',function(){ console.log('server closed keep existing connection');});  tcpserver.on('error',function(error){                 console.log(error.code);                 });  tcpserver.listen(8000,function(){                 console.log('tcp server has been bound');                 }); 

i got answer after looking event section.

close handler called when existing tcp connections closed, not after close method invocation. strange per documentation correct behavior.

event: 'close'#

emitted when server closes. note if connections exist, event not emitted until connections ended.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -