0.0.9 • Published 11 years ago
net-socket-reconnect v0.0.9
net-reconnect
Makes net.connect() and net.createConnection() auto reconnect.
Usage
var reconnect= require('net-socket-reconnect')
var client= reconnect({port: 8080, reconnectInterval: 150}) // no change to original APIOptions
reconnectOnErrorreconnect on 'error', default falsereconnectOnEndreconnect on 'end', default falsereconnectOnClosereconnect on 'close', default truereconnectOnTimeoutreconnect on 'timeout', default falsereconnectOnCreatereconnect after initial connect failed, default falsereconnectIntervalinterval between tries, default 300reconnectTimesmax retries, default 50
note: 50 * 300= 15,000. That's 15 seconds of retrying and then giving up with
reconnectFailedevent
Methods
Except the original events, there's a few new ones:
client.reconnect()ends current connection and reconnects; or simple reconnects if you set all auto reconnect options to false (and decided to deal with it manually)client.stopReconnect()stops any further reconnect actionsclient.startReconnect()restarts reconnectclient.getReconnect()get current reconnect state: true/on, or false/off
Events
Except the original events, there's a two new ones:
reconnectwhen successfuly reconnectedreconnectFailedwhen reconnect reached reconnectTimes
important: every successful reconnect will also emit
'connect'event by net.Socket, so plan your client.on('connect', function(){}) callbacks
Installation
npm install net-socket-reconnectMIT License