Code Monkey home page Code Monkey logo

kalm's Introduction

# Kalm *The Socket Optimizer*

Kalm Build Status Dependencies Status Code Climate Gitter


Simplify and optimize your Socket communications with:

  • Easy-to-use single syntax for all protocols
  • Configurable packet bundling (High-level Naggle's algorithm implementation)
  • Multiplexing for all protocols
  • Ultra-flexible and extensible, load your own adapters and encoders

Compatibility

  • NODE >= 6.0.0

  • Webpack 1 || 2.1.x

Performance analysis

Requests per minute

Benchmarks based on a single-thread queue test with Kalm default bundling settings

Bytes transfered

Number of protocol overhead bytes saved per request

Installation

npm install kalm

Usage

Server

    var Kalm = require('kalm');

    // Create a server, listening for incoming connections
    var server = new Kalm.Server({
      port: 6000,
      adapter: 'udp',
      encoder: 'json',
      channels: {
        messageEvent: function(data) {               // Handler - new connections will register to these events
          console.log('User sent message ' + data.body);
        }
      }
    });

    // When a connection is received, send a message to all connected users
    server.on('connection', function(client) {    // Handler, where client is an instance of Kalm.Client
      server.broadcast('userEvent', 'A new user has connected');  
    });
    

Client

    // Opens a connection to the server
    var client = new Kalm.Client({
      hostname: '0.0.0.0', // Server's IP
      port: 6000, // Server's port
      adapter: 'udp', // Server's adapter
      encoder: 'json', // Server's encoder
      channels: {
        'userEvent': function(data) {
          console.log('Server: ' + data);
        }
      }
    });

    client.send('messageEvent', {body: 'This is an object!'}); 
    client.subscribe('someOtherEvent', function() {});

Documentation

API docs

Adapters

Encoders

Loading custom adapters

The framework is flexible enough so that you can load your own custom adapters, encoders or middlewares

    // Custom adapter loading example
    var Kalm = require('kalm');
    var WebRTC = require('kalm-webrtc');
    var msgpack = require('kalm-msgpack');

    Kalm.adapters.register('webrtc', WebRTC);
    Kalm.encoders.register('msg-pack', msgpack);

    var server = new Kalm.Server({
      port: 3000,
      adapter: 'webrtc',
      encoder: 'msg-pack'
    });

Run tests

npm test

Logging

Kalm uses debug

export DEBUG=kalm

You can also gather optimization statistics by piping kalm:stats

export DEBUG=kalm:stats myApp.js > stats.log

Roadmap

Milestones

Presentations

kalm's People

Contributors

fed135 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.