npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

callosum-server-tcp

v0.1.0

Published

TCP server for Callosum: a self-balancing distributed services protocol

Downloads

4

Readme

callosum-server-tcp

Stability: 1 - Experimental

NPM version

TCP Server for Callosum: a self-balancing distributed services protocol.

Usage

var CallosumServer = require('callosum-server-tcp');
var callosumServer = new CallosumServer({
    host: 'localhost',
    port: 4040
});

callosumServer.on('connection', function (conn) {
    // one of the active connections from clients that has been assigned a slot
    // do stuff with `conn` 
});

callosumServer.on('slot request', function (callback) {
    // assign a new slot
    var slot = /* pick lowest slot available (probably from a heap), ex: */ 0;
    return callback(slot); 
});

callosumServer.on('slot free', function (slot) {
    // free the slot
    // probably put it back on the heap 
});

callosumServer.listen(function () {
    console.log('server listening...'); 
});

Tests

npm test

Overview

TCP Server for Callosum, which is an open-source implementation of Indeed's Boxcar: A self-balancing distributed services protocol.

Callosum TCP Server Protocol

When a new client connects to a TCP CallosumServer, the server will respond with the slot number assigned to the connection by sending a slot number followed by \r\n. For example, for slot 13:

13\r\n

This is all the information necessary for a client to either accept the slot, and keep the connection, or reject the slot by breaking the connection.

Documentation

CallosumServer

CallosumServer.listen(options, [callback])

  • options: See new CallosumServer(options) options.
  • callback: See callosumServer.listen(callback) callback.
  • Return: Object An instance of CallosumServer with server running.

Creates a new CallosumServer and starts the server.

new CallosumServer(options)

  • options: Object
    • host: String (Default: undefined) Hostname for the server to listen on. If not specified, the server will accept connections directed to any IPv4 address (INADDR_ANY).
    • port: Integer (Default: 4040) Port number for the server to listen on.

Creates a new CallosumServer instance.

callosumServer.close([callback])

  • callback: Function (Default: undefined) function () {} Optional callback to call once the server is stopped.

Stops the server from accepting new connections.

callosumServer.listen([callback])

  • callback: Function (Default: undefined) function () {} Optional callback to call once the server is up.

Starts the server to listen to new connections.

Event connection

  • function (connection) {}
    • connection: Socket object The connection object.

Emitted once the connection is assigned a new slot via a callback to the slot request event.

Event error

  • function (error) {}
    • error: Object An error that occurred.

Emitted when CallosumServer encounters an error. If no handler is registered, an exception will be thrown.

Event slot free

  • function (slot) {}
    • slot: Integer Slot number to free.

Emitted when the a connection with previously assigned slot is broken.

Event slot request

  • function (callback) {}
    • callback: Function function (error, slot) {} The callback to call with the next available slot number.

Emitted when a new connection from a client is made.

Sources