node-snet
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

Node Simple Network

NodeJS port of LuaJIT SNet

SNET - cross-platform, open source, network library

Install

npm install node-snet
yarn add node-snet
pnpm add node-snet

Example

import { Server, BitStream } from 'node-snet';

const server = new Server({
  port: 11321,
  clientTimeout: 10000,
  ipVersion: 'v6'
});

server.on('ready', () => {
  console.log(`@server: started at port ${server.port}`);
});

server.on('onReceivePacket', async (id, bs, address, port) => {
  console.log(`onReceivePacket: ${address}:${port}`, id, bs.toString());
  if (id === 1) {
    const data = new BitStream();
    data.writeString('snetwork');
    server.sendAll(2, data, 4);
  }
});

server.on('onClientUpdate', async (address, port, type) => {
  console.log(`onClientUpdate ${address}:${port}:`, type);
});

server.listen();

// or change port
// server.listen(7788).then(() => console.log('listen'))

Package Sidebar

Install

npm i node-snet

Weekly Downloads

15

Version

1.2.0

License

GPL-3.0

Unpacked Size

65.4 kB

Total Files

7

Last publish

Collaborators

  • whyrinki