Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Cocker, a socket module to handle connection retries.
JavaScript

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
.jshintrc
.npmignore
.travis.yml
LICENSE
Readme.md
index.js
package.json

Readme.md

Cocker

NPM VERSION CODACY BADGE CODECLIMATE CODECLIMATE-TEST-COVERAGE LICENSE

TRAVIS CI BUILD BUILD STATUS DEVDEPENDENCY STATUS NPM DOWNLOADS

NPM GRAPH1

NPM GRAPH2

status views views 24h

For nodeJS versions < v0.10.x, check v0.8.x branch.

Install

$ npm install cocker [-g]

require:

var Cocker  = require( 'cocker' );

Run Tests

$ cd cocker/
$ npm test

Constructor

Create an instance, the argument within [ ] is optional.

Cocker( [ Object opt ] ) : Cocker
// or
new Cocker( [ Object opt ] ) : Cocker

Options

Cocker supports net.Socket options:

cocker_opt = {
 address : {
    host : '127.0.0.1'
    , port : 0
    , family : null
 }
 , path : undefined
 , connection : {
    encoding : null
    , keepAlive : true
    , timeout : 0
    , noDelay : true
    , allowHalfOpen : false
 }
 // Cocker custom options
 , reconnection : {
    trials : 3
    , interval : 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.sqrt( 5 ) + 1 ) / 2
 }
}

Properties

Cocker custom properties:

// a property that holds the initial config object:
Cocker.options : Object

// current number of connection attempts
Cocker.attempts : Number

// a flag, also useful to manually disable/re-enable/check reconnection-loop
Cocker.lost : Boolean

// the last interval in millis between connection attempts.
Cocker.lapse : Number

Methods

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#run( [ Object cocker_options ] ) : undefined

// Use this method to end the connection without re-connecting.
Cocker#bye( [ Buffer data | String message [, String encoding ] ] ) : undefined

Events

All the events from net.Socket module are inherited.

Cocker custom events:

/*
 * Connection was established.
 */
'online' : function ( Object address )

/*
 * 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 )

MIT License

Copyright (c) 2015 < Guglielmo Ferri : 44gatti@gmail.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.

GA

Something went wrong with that request. Please try again.