@neko-net/rusty-enet
v0.1.3
Published
Node.js binding for [ENet](http://enet.bespin.org/) via [rusty_enet](https://github.com/neko-net/rusty_enet), built with [napi-rs](https://napi.rs).
Readme
@neko-net/rusty-enet
Node.js binding for ENet via rusty_enet, built with napi-rs.
ENet is a thin UDP networking layer designed for real-time applications like games, providing optional reliable, sequenced packet delivery over multiple channels.
Install
npm install @neko-net/rusty-enetPrebuilt binaries for Linux (x64, arm64), macOS (x64, arm64), and Windows (x64, arm64).
Quick start
const { EnetHost, PacketKind } = require('@neko-net/rusty-enet');
async function main() {
// Server
const server = new EnetHost('127.0.0.1:0', { peerLimit: 1, channelLimit: 2 });
const port = (await server.getLocalAddr()).split(':').pop();
// Client
const client = new EnetHost('127.0.0.1:0', { peerLimit: 1, channelLimit: 2 });
await client.connect(`127.0.0.1:${port}`, 2, 0);
// Connect events fire on both sides
await server.service(); // { eventType: 'Connect', peerId: 0, data: 0 }
await client.service(); // { eventType: 'Connect', peerId: 0 }
// Send a reliable packet
await client.send(0, 0, Buffer.from('hello'), PacketKind.Reliable);
const recv = await server.service();
console.log(recv.packet.toString()); // "hello"
server.close();
client.close();
}
main();License
MIT
