Socket
Socket
Sign inDemoInstall

raknet-node

Package Overview
Dependencies
3
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    raknet-node

Nodejs bindings to rust-raknet native library.


Version published
Weekly downloads
327
decreased by-17.84%
Maintainers
1
Install size
8.77 MB
Created
Weekly downloads
 

Readme

Source

raknet-node

Build Status NPM version ChatOnDiscord

Nodejs bindings to rust-raknet native library.

Install

npm install raknet-node

Prebuilds are provided for 64-bit Windows 10, Linux and OSX. If a prebuild does not work, please create an issue.

Build

napi build --release

Usage

Compatible node-raknet-native

raknet-node provides the same set of interfaces as node-raknet-native, which you can use in a similar way. But they still have some differences. For example we have to require the first byte of the packet to be 0xfe.

const { Client, Server, PacketPriority, PacketReliability } = require('raknet-node')
// The third paramater is for game type, you can specify 'minecraft' or leave it blank for generic RakNet
const client = new Client('127.0.0.1', 19130)
// hostname, port, serverOptions
const server = new Server('0.0.0.0', 19130)
server.listen()
client.connect()
client.on('encapsulated', (buffer) => {
  console.assert(buffer.cmp(Buffer.from([0xfe ,1, 2, 3])))
})

server.on('openConnection', (client) => {
  client.send(Buffer.from([0xfe ,1, 2, 3]), PacketPriority.HIGH_PRIORITY, PacketReliability.UNRELIABLE, 0)
})

Asynchronous usage

The RaknetClient and RaknetServer classes are JS wrappers for the internal RaknetSocket and RaknetListener classes implemented in Rust in src/. All methods use asynchronous wrappers.

const raknet = require('raknet-node')
const assert = require('assert');

async function main(){
	address = "127.0.0.1:19132"
	server = await raknet.RaknetServer.bind(address)
	console.log("bind to : " + address)
	
	client1 = await raknet.RaknetClient.connect(address)

	console.log("connect to : " + address + " success")

	client2 = await server.accept()

	await client1.send(Buffer.from([0xfe ,1, 2, 3]))
	await client2.send(Buffer.from([0xfe ,1, 2, 3]))

	buf1 = await client1.recv()
	buf2 = await client2.recv()

	assert(buf1.compare(buf2) == 0)

	return "finished"
}

main()
 .then(console.log)
 .catch(console.error)

Lisence

MIT - https://github.com/b23r0/raknet-node/blob/main/LICENSE

Keywords

FAQs

Last updated on 05 Oct 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc