Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-multi-socketservers

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-multi-socketservers

A multi http & socket servers manager, based on node-multi-webserver

  • 0.2.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

node-multi-socketservers

A multi http and socket servers manager, based on node-multi-webserver

Installation

$ npm install node-multi-socketservers

Features

  • run the same server with different configurations (ports, ssl, etc...)
  • socket communication with all servers

Doc

  • see node-multi-webservers documentation for webservers management

  • connection(function eventListener) : return Promise instance eventListener((socket[ , server ]) => {})

  • emit(string eventName[, mixed data]) : return Promise instance

  • broadcast(SocketIO.Socket socket, http.Server server, string eventName, [, mixed data]) : return Promise instance broadcast on all servers

  • removeAllListeners(string|array eventNames) : return Promise instance remove all listener of an event or an array of events for all the servers and sockets

Examples

with express

const http = require("http"),
      https = require("https"),
      express = require("express"),
      multiservers = require("node-multi-socketservers");

let servers = new multiservers(),
    app = express().get("/", (req, res) => {
  res.set("Content-Type", contentType).send(message);
});

return servers.addServer({
  port: 80,
  name: "http server"
}).then(() => {

  return servers.addServer({
    port: 443,
    name: "secure server",
    ssl: true,
    key: "YOUR_PRIVATE_KEY",
    cert: "YOUR_CERTIFICATE"
  });

}).then(() => {

  return servers.addServer({
    port: 1337,
    name: "admin server",
    key: "YOUR_PRIVATE_KEY",
    cert: "YOUR_CERTIFICATE"
  });

}).then(() => {

  return servers.setTimeout(2 * 1000);

}).then(() => {

  return servers.listen(app);

}).then(() => {

  return servers.connection((socket, server) => {

    servers.broadcast(socket, server, "newconnection");

    socket.on("disconnect", () => {
      servers.broadcast(socket, server, "disconnection");
    });

  });

}).catch((err) => {

  console.log(err);

  servers.release().catch((err) => {
    console.log(err);
  });

});

native

const http = require("http"),
      https = require("https"),
      multiservers = require("node-multi-socketservers");

let servers = new multiservers();

return servers.addServer({
  port: 80,
  name: "http server"
}).then(() => {

  return servers.addServer({
    port: 443,
    name: "secure server",
    ssl: true,
    key: "YOUR_PRIVATE_KEY",
    cert: "YOUR_CERTIFICATE"
  });

}).then(() => {

  return servers.addServer({
    port: 1337,
    name: "admin server",
    key: "YOUR_PRIVATE_KEY",
    cert: "YOUR_CERTIFICATE"
  });

}).then(() => {

  return servers.setTimeout(2 * 1000);

}).then(() => {

  return servers.listen((req, res) => {

    res.writeHead(200, {"Content-Type": contentType});
    res.end("hello world, from http:80, https:443 or https:1337");

  });

}).then(() => {

  return servers.connection((socket, server) => {

    servers.broadcast(socket, server, "newconnection");

    socket.on("disconnect", () => {
      servers.broadcast(socket, server, "disconnection");
    });

  });

}).catch((err) => {

  console.log(err);

  servers.release().catch((err) => {
    console.log(err);
  });

});

Tests

$ gulp

License

ISC

Keywords

FAQs

Package last updated on 03 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc