| English | 简体中文 |
KCP Protocol for Node.js
A fork of node-kcp, rewritten using node-addon-api
- High Performance: 30%-40% reduction in average RTT compared to traditional ARQ protocols like TCP
- Low Latency: Maximum RTT reduced by 3x compared to TCP
- Lightweight: Distributed as a single source file
- Modern API: Built with node-addon-api for better Node.js compatibility
- Cross Platform: Supports Windows, Linux, and macOS
npm install node-kcp-x
npm install -g node-gyp prebuildify
git clone https://github.com/bruce48x/node-kcp
cd node-kcp
npm i
npm run build
npm run install
node test/udpserver.js
node test/udpclient.js
# Run server
node examples/server.js
# Run client
node examples/client.js
# Run stream server
node examples/stream-server.js
# Run stream client
node examples/stream-client.js
const kcp = require('node-kcp-x');
const Kcp = kcp.KCP;
// Create KCP instance
const kcpObj = new Kcp(conv, context);
// Set output callback
kcpObj.output((data, size, context) => {
// Send data to network
});
// Send data
kcpObj.send(buffer);
// Receive data
const buffer = kcpObj.recv();
// Update KCP state
kcpObj.update(timestamp);
// Check next update time
const nextUpdate = kcpObj.check(timestamp);
If you want to use node-kcp in pomelo server, you need pomelo-kcp
Apache-2.0