0.0.9 • Published 10 years ago

net-socket-reconnect v0.0.9

Weekly downloads
97
License
MIT
Repository
github
Last release
10 years ago

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

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago