Skip to content

cyyynthia/hazeljs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HazelJS

ko-fi
License npm

TypeScript implementation of the Hazel-Networking C# net library.

Note: This is alpha-quality software which is most likely not suitable for production applications. It hasn't really been tested and the probability of it exploding catastrophically is 0.9. It's also very likely to receive breaking changes at any given time.

Requirements

NodeJS 14+ (HazelJS is esm only)

Installation

npm i @cyyynthia/hazeljs
yarn add @cyyynthia/hazeljs
pnpm i @cyyynthia/hazeljs

Usage

The docs only shows basic usage, and aren't super detailed. I'll eventually add better docs once the lib is more stable and in a production-ready shape. For now, autocomplete is your best friend:tm:

Server

Here's a basic example:

import { Server } from '@cyyynthia/hazeljs'

const server = new Server() // To create an IPv6 server: new Server(true)
server.on('connection', (connection, hello) => {
  console.log(`New connection from ${connection.remote.address}:${connection.remote.port}`)
  console.log(`Hello payload:`, hello)

  connection.on('message', (msg) => {
    console.log('Message received', msg)
    // Here we just echo it back, but you'd normally process the message and eventually
    // reply with a more appropriated response.
    connection.sendNormal(msg)
  })

  connection.on('close', () => {
    console.log(`Connection with ${connection.remote.address}:${connection.remote.port} closed.`)
  })
})

server.listen(1337, '127.0.0.1')

Client

import { Client } from '@cyyynthia/hazeljs'

const client = new Client() // To create an IPv6 client: new Client('127.0.0.1', 1337, true)

client.on('connected', () => {
  console.log('Connected!')

  client.sendNormal(...)
})

client.on('message', (msg) => {
  console.log('Message received', msg)
})

client.connect()

About

TypeScript implementation of the Hazel-Networking C# net library.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published