net-socket-reconnect
v0.0.9
Published
makes net.connect() and net.createConnection() auto reconnect
Downloads
335
Maintainers
Readme
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 API
Options
reconnectOnError
reconnect on 'error', default falsereconnectOnEnd
reconnect on 'end', default falsereconnectOnClose
reconnect on 'close', default truereconnectOnTimeout
reconnect on 'timeout', default falsereconnectOnCreate
reconnect after initial connect failed, default falsereconnectInterval
interval between tries, default 300reconnectTimes
max retries, default 50
note: 50 * 300= 15,000. That's 15 seconds of retrying and then giving up with
reconnectFailed
event
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:
reconnect
when successfuly reconnectedreconnectFailed
when 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-reconnect
MIT License