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
- Can be used between servers or in the browser
- NODE >= 4.0.0
Requests per minute
Benchmarks based on a single-thread queue test with Kalm default bundling settings
Bytes transfered
Bundled calls means that you only send the protocol headers (40 bytes + application overhead) once. This makes a huge difference when you need to send a large number of small packets.
npm install kalm
Server
const Kalm = require('kalm');
// Create a server, listening for incoming connections
let server = new Kalm.Server({
port: 6000,
adapter: 'udp',
encoder: 'json',
channels: {
messageEvent: (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', (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
let 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': (data) => {
console.log('Server: ' + data);
}
}
});
client.send('messageEvent', {body: 'This is an object!'});
client.subscribe('someOtherEvent', function() {});- ipc (bundled)
- tcp (bundled)
- udp (bundled)
- kalm-websocket
- kalm-webrtc (On hold)
- json (bundled)
- kalm-msgpack
- kalm-snappy
- kalm-compactr (In-dev)
The framework is flexible enough so that you can load your own custom adapters, encoders or middlewares
// Custom adapter loading example
const Kalm = require('kalm');
const ws = require('kalm-websocket');
const msgpack = require('kalm-msgpack');
Kalm.adapters.register('ws', ws);
Kalm.encoders.register('msg-pack', msgpack);
let server = new Kalm.Server({
port: 3000,
adapter: 'ws',
encoder: 'msg-pack'
});npm test
Kalm uses debug
export DEBUG=kalm
You can also gather optimization statistics by piping kalm:stats
export DEBUG=kalm:stats myApp.js > stats.log
- JS Montreal - June 14th 2016

