Skip to content

About

Rusty Enet NAPI

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

@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-enet

Prebuilt 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

About

Rusty Enet NAPI

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages