@kiyasov/sticky-session

1.2.0 • Public • Published

stickySession

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

Installation

npm install @kiyasov/sticky-session --save-dev

Usage

import http from "http";
import cluster from "cluster";
import StickySession from "../lib";
import SocketIO from "socket.io";
import express from "express";
import SocketIORedis from "socket.io-redis";

let stickySession = new StickySession({
  listen: [3000, '127.0.0.1'],
  workers: 4
});

const app = express();
const server = http.Server(app);
const socket = SocketIO(server);

socket.adapter(SocketIORedis({ host: '127.0.0.1', port: 6379 }));

if (!stickySession.listen(server)) {
  // Master code
  server.once("listening", () => console.log("server started on 3000 port"));
} else {
  socket.on("connection", client => {
      console.log('a user connected');
      
      client.on("disconnect", client => {
        console.log('a user disconnect');
      });
  });
}

Simple

Readme

Keywords

none

Package Sidebar

Install

npm i @kiyasov/sticky-session

Weekly Downloads

0

Version

1.2.0

License

ISC

Unpacked Size

14.4 kB

Total Files

9

Last publish

Collaborators

  • kiyasov