net-socket-reconnect

0.0.9 • Public • Published

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 false
  • reconnectOnEnd reconnect on 'end', default false
  • reconnectOnClose reconnect on 'close', default true
  • reconnectOnTimeout reconnect on 'timeout', default false
  • reconnectOnCreate reconnect after initial connect failed, default false
  • reconnectInterval interval between tries, default 300
  • reconnectTimes 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 actions
  • client.startReconnect() restarts reconnect
  • client.getReconnect() get current reconnect state: true/on, or false/off

Events

Except the original events, there's a two new ones:

  • reconnect when successfuly reconnected
  • reconnectFailed 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

Package Sidebar

Install

npm i net-socket-reconnect

Weekly Downloads

117

Version

0.0.9

License

MIT

Last publish

Collaborators

  • david_sky