Socket
Book a DemoInstallSign in
Socket

kalm

Package Overview
Dependencies
Maintainers
2
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kalm

The socket optimizer

latest
Source
npmnpm
Version
8.0.1
Version published
Maintainers
2
Created
Source

Kalm
Kalm

The Socket Optimizer


  • Easy-to-use syntax unified across protocols
  • Flexible and extensible, create your own transports and buffering strategies
  • Can be used between servers or in the browser
  • Lower resource footprint and better throughput than plain sockets
  • Zero dependencies and can be bundled down to ~5kb!

Performance

perf

The performance gain comes from buffering packets before sending them- eventually sending batches instead of individual packages. The more traffic getting processed, the better the improvement. Many strategies are offered as routines. You can read more about the packet buffering algorithm here

Install

Install the core package

npm install kalm

Install the transport layer ('tcp' for example)

npm install @kalm/tcp

Usage

Server

const kalm = require('kalm');
const ws = require('@kalm/ws');

const server = kalm.listen({
  port: 8800,
  transport: ws(),
  routine: kalm.routines.tick({ hz: 5 }), // Sends packets at a frequency of 5 Hz (200ms)
  host: '0.0.0.0',
});

server.on('connection', (client) => {
  client.subscribe('channel1', (body, context) => {
    // When receiving messages from this client on "channel1"
    console.log(body) //
    console.log(context) //
  });

  // Sends a message to all clients on "channel2"
  server.broadcast('channel2', 'some message');
});

Client

const kalm = require('kalm');
const ws = require('@kalm/ws');

const client = kalm.connect({
  host: '0.0.0.0',
  port: 8800,
  transport: ws(),
  routine: kalm.routines.realtime(),
});

client.on('connect', () => {
  client.subscribe('channel1', (body, context) => {
    // When receiving messages from the server on "channel1"
    console.log(body); // 
    console.log(context); //
  });

  // Sends a message to the server on "channel2"
  client.write('channel2', 'hello world');
});

To see working implementations, check out our examples folder.

Documentation

[Read more]

Logging

Kalm uses the NODE_DEBUG environment variable. Just include kalm in your value.

Example:

NODE_DEBUG=net,kalm node myApp.js

Events

Kalm servers offers events to track when packets are processed by routines or when a raw frame is received.

Server EventPayloadDescription
errorError(server, client) Emits on errors.
readyvoid(server) Indicates that the server is now actively listening for new connections
connectionClient(server) Indicates that a client has successfully connected

Kalm clients offers events to track when packets are processed by routines or when a raw frame is received.

Client EventPayloadDescription
errorError(server, client) Emits on errors.
connectvoid(client) Indicates that a client has successfully connected
disconnectvoid(client) Indicates that a client has disconnected
frame{ body: Partial<RawFrame>, payloadBytes: number }(client) Triggered when receiving payloads, can be used to intercept messages from non-kalm counterparts.

Testing

npm test

npm run bench

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

If you think of something that you want, open an issue or file a pull request, we'll be more than happy to take a look!

License

Apache 2.0 2025 Frederic Charette

Keywords

framework

FAQs

Package last updated on 08 Aug 2025

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