1.1.2 • Published 8 years ago

sticky-session v1.1.2

Weekly downloads
2,726
License
MIT
Repository
-
Last release
8 years ago

Sticky session

A simple performant way to use socket.io with a cluster.

Installation

npm install sticky-session

Usage

var cluster = require('cluster'); // Only required if you want the worker id
var sticky = require('sticky-session');

var server = require('http').createServer(function(req, res) {
  res.end('worker: ' + cluster.worker.id);
});

if (!sticky.listen(server, 3000)) {
  // Master code
  server.once('listening', function() {
    console.log('server started on 3000 port');
  });
} else {
  // Worker code
}

Simple

Reasoning

Socket.io is doing multiple requests to perform handshake and establish connection with a client. With a cluster those requests may arrive to different workers, which will break handshake protocol.

Sticky-sessions module is balancing requests using their IP address. Thus client will always connect to same worker server, and socket.io will work as expected, but on multiple processes!

Note about node version

sticky-session requires node to be at least 0.12.0 because it relies on net.createServer's pauseOnConnect flag.

A deeper, step-by-step explanation on how this works can be found in elad/node-cluster-socket.io

LICENSE

This software is licensed under the MIT License.

Copyright Fedor Indutny, 2015.

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.

@tyz-wallet/tyz-wallet-core-serviceconsole_data_apibitcore-wallet-service-sprc@everything-registry/sub-chunk-2827sexcore-wallet-servicescherialifetioncore-wallet-serviceliverecordlocomotive-primusj316-translatorlioncore-wallet-servicemcore-wallet-service-matrixbitmotion_industrykeoken-wallet-servicemulticore-wallet-servicemxbitcore-wallet-serviceltzcore-wallet-servicematrixbitcore-wallet-servicenodespringnodespring-ekapolispay-wallet-servicepotcore-wallet-servicepuppeteer-servicepcxcore-wallet-serviceraiden-wallet-service@adora-wallet/adoracore-wallet-service@bitrupee/bitcore-wallet-service@captemulation/bitcore-wallet-service@abcpros/bitcore-wallet-service@ducatus/bitcore-wallet-service@ducatus/ducatus-wallet-service-rev@ducatus/ducatuscore-wallet-service@infinitebrahmanuniverse/nolb-sti@tecracoin/bitcore-wallet-service-tcr@o0o2022/bitcore-wallet-service@o0o2022sg/bitcore-wallet-service@owstack/wallet-service@owstack/btc-wallet-service@owstack/bch-wallet-service@owstack/ltc-wallet-service@swtrse/bitcore-wallet-service@sotatek-anhdao/bitcore-wallet-service@sotatek-anhdao/react-native-bitcore-wallet-serviceapocket-apiarcane-corebtcnano-wallet-servicebitcore-wallet-service-anonbitcore-wallet-service-axebitcore-wallet-service-btczbitcore-wallet-service-colxbitcore-wallet-service-crownbitcore-wallet-service-divibitcore-wallet-service-ducatusbitcore-wallet-service-dynamicbitcore-wallet-service-exccbitcore-wallet-service-matrixbitbitcore-wallet-service-mxbitbitcore-wallet-service-mycoinbitcore-wallet-service-polisbitcore-wallet-service-raidenbitcore-wallet-service-rapturebitcore-wallet-service-tcrbitcore-wallet-service-terracoinbitcore-wallet-servicebitcore-wallet-service-dashberycore-wallet-servicebivcore-wallet-serviceceres-frameworkdeocoincore-wallet-servicedigibytejs-wallet-servicedigicore-wallet-serviceeonacore-serviceexortducatus-wallet-serviceducatus-wallet-service-2fcash-wallet-serviceflexbiz-server
1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.3

8 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.1.0

12 years ago

0.0.5

13 years ago

0.0.4

13 years ago

0.0.3

13 years ago

0.0.2

13 years ago