Cocker, a socket module to handle reconnection retries.
For nodeJS versions < v0.10.x, check v0.8.x branch.
$ npm install cocker [-g]
var Cocker = ;
$ cd cocker/$ npm test
Create an instance, the argument within [ ] is optional.
: Cocker// orObject opt : Cocker
Cocker supports net.Socket options:
cocker_opt =address :host : '127.0.0.1'port : 0family : nullpath : undefinedconnection :encoding : nullkeepAlive : truetimeout : 0noDelay : trueallowHalfOpen : false// Cocker custom optionsreconnection :trials : 3interval : 1000/** A value to use for calculating the pause between two* connection attempts. Default value is the golden ratio.* Final value is calculated as:* interval * Math.pow( factor, curr.attempts + 1 )*/factor : Math + 1 / 2
Cocker custom properties:
// a property that holds the initial config object:Cockeroptions : Object// current number of connection attemptsCockerattempts : Number// a flag, also useful to manually disable/re-enable/check reconnection-loopCockerlost : Boolean// the last interval in millis between connection attempts.Cockerlapse : Number
All the methods from net.Socket module are inherited.
Arguments within [ ] are optional, '|' indicates multiple type for an argument.
// connect to socket, optionally (re-)configuring the connection.Cocker# : undefined// Use this method to end the connection without re-connecting.Cocker# : undefined
All the events from net.Socket module are inherited.
Cocker custom events:
/** Connection was established.*//** Connection is down ( on first 'close' event for the socket).*/'offline' : function ( Object address )/** k is the number of current connection attempt.*/'attempt' : function ( Number k, Object address, Number millis )/** Connection is definitively lost ( after opt.reconnection.trials times ).*/'lost' : function ( Object address )
Copyright (c) 2015 < Guglielmo Ferri : email@example.com >
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.