Nodejs reconnect network connection

I have a network client connection with a socket (using net.createConnection (port, host). This works great.

However, sometimes there is a chance that the server will delete the connection, and I would like the network connection to automatically turn on when the server is up and running

I can capture the on ('end') event to catch the initial disconnect and try to reconnect.

However, how can I check if the client is connected because I want to repeat every n milliseconds in the deferral strategy

+5
source share
2 answers

end , -, , connect , -.

+5

, .

if ( !client.readable )
    client.connect(PORT,HOST);
else
    logger.debug('Attempt to reconnect on an active connection. Ignored.');

client.readable - - . , . client.writable .

, END CLOSE (, VPN, ..)

0

All Articles