Thanks to visit codestin.com
Credit goes to github.com

Skip to content

A high-performance Node.js binding for the ENet reliable UDP networking library. Built specifically for Growtopia private server development with modern JavaScript APIs. πŸš€

License

Notifications You must be signed in to change notification settings

YoruAkio/GTEnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

51 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌐 GTEnet

A high-performance Node.js binding for the ENet reliable UDP networking library. Built specifically for Growtopia private server development with modern JavaScript APIs. πŸš€

Warning

This project is in early development. Expect breaking changes and limited features. Use at your own risk! Tested on:

  • Linux ( Arch Linux )
  • Windows ( MSVC & MSYS2 )
  • MacOS ( Soon )

πŸ“‹ Requirements

# Node.js 18.x
# Python 3.1x

πŸ“¦ Installation

npm install gtenet

or with Bun:

bun add gtenet

# you might get message blocked postinstall, you can run it manually
bun pm trust gtenet

πŸš€ Quick Start

Running the Examples

Start a server:

node run example/server

# or

bun run example/server

In another terminal, start a client:

node run example/client

# or

bun run example/client

πŸ“– Basic Usage

πŸ–₯️ Server Example

import { Server } from 'gtenet';

// Create a server with automatic port checking
const server = await Server.create({
  ip: '127.0.0.1', // Server IP address
  port: 17091, // Server port
  maxPeer: 32, // Maximum connected clients
});

// Set up event handlers with chaining
server
  .on('connect', event => {
    console.log('πŸŽ‰ Client connected:', event.peer);
  })
  .on('disconnect', event => {
    console.log('πŸ‘‹ Client disconnected:', event.peer);
  })
  .on('receive', event => {
    console.log('πŸ“¨ Received:', event.data.toString());
    // Echo the message back
    server.send(event.peer, 0, `Echo: ${event.data.toString()}`);
  })
  .on('error', err => {
    console.error('❌ Server error:', err.message);
  });

// Start listening for connections
await server.listen();

πŸ’» Client Example

import { Client } from 'gtenet';

// Create a client
const client = new Client({
  ip: '127.0.0.1', // Server IP
  port: 17091, // Server port
});

// Set up event handlers
client
  .on('connect', event => {
    console.log('πŸ”— Connected to server!');
    client.send(0, 'Hello Server! πŸ‘‹');
  })
  .on('disconnect', event => {
    console.log('πŸ’” Disconnected from server');
  })
  .on('receive', event => {
    console.log('πŸ“© Server says:', event.data.toString());
  })
  .on('error', err => {
    console.error('❌ Client error:', err.message);
  });

// @note connect and start event loop
await client.connect();

πŸ“„ License

This project is licensed under the MIT License. See LICENSE for more information.

πŸ™ Acknowledgements

  • 🌐 ENet - ENet reliable UDP networking library
  • βš™οΈ Node-Addon-API - Node.js addon API for native modules
  • 🌱 growtopia.js - High-performance Growtopia private server framework

οΏ½πŸ“’ Special Thanks

Thanks to these people

About

A high-performance Node.js binding for the ENet reliable UDP networking library. Built specifically for Growtopia private server development with modern JavaScript APIs. πŸš€

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published