Package Exports
- raknet-native
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (raknet-native) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
node-raknet-native
Native RakNet bindings for Node.js
Install
npm install extremeheat/node-raknet-nativePrebuilds are provided for 64-bit Windows 10, Linux and macOS Catalina. If a prebuild does not work, create an issue and set enviornment variable FORCE_BUILD to force a manual build.
See #Usage below.
Build
You must clone the repository recursively.
git clone --recursive https://github.com/extremeheat/node-raknet-native.git && cd node-raknet-native
npm installBuild on mac
You need to install xcode utilities first:
xcode-select --installUsage
A simple generic RakNet example:
const { Client, Server, PacketPriority, PacketReliability } = require('raknet-native')
// hostname, port, optionalGameType
// The third paramater is for game type, you can specify 'minecraft' or leave it blank for generic RakNet
const client = new RakClient('127.0.0.1', 19130)
// hostname, port, serverOptions
const server = new RakServer('0.0.0.0', 19130, { maxConnections: 3 })
server.listen()
client.connect()
client.on('encapsulated', (buffer) => {
console.assert(buffer.toString() == '\xA0 Hello world')
})
server.on('openConnection', (client) => {
client.send(Buffer.from('\xA0 Hello world'), PacketPriority.HIGH_PRIORITY, PacketReliability.UNRELIABLE, 0)
})For Minecraft Bedrock, use:
const { Client, Server, PacketPriority, MCPingMessage } = require('raknet-native')
const client = new RakClient('127.0.0.1', 19130, 'minecraft')
const server = new RakServer('0.0.0.0', 19130, { maxConnections: 3, minecraft: { message: new MCPingMessage().toString() } })Exported API
export class Client extends EventEmitter {
constructor(hostname: string, port: number, game?: string)
ping(): void
connect(): Promise<void>
close(): void
on(event: 'pong', params: ({ extra: Buffer }) => void)
on(event: 'encapsulated', params: ({ buffer: Buffer }) => void)
send(message: Buffer, priority: PacketPriority, reliability: PacketReliability, orderingChannel: number, broadcast?: boolean): number
}
export class ServerClient {
close():void
send(message: Buffer, priority: PacketPriority, reliability: PacketReliability, orderingChannel: number, broadcast?: boolean): number
}
export class Server {
constructor(hostname: string, port: number, options: ServerOptions)
connections: Map<string, Server>
listen(): Promise<void>
send(address: string, port: number, message: Buffer, priority: PacketPriority, reliability: PacketReliability, orderingChannel: number, broadcast?: boolean): number
on(event: 'encapsulated', params: ({ buffer: Buffer }) => void)
on(event: 'openConnection', params: (client: ServerClient) => void)
on(event: 'closeConnection', params: (cient: ServerClient) => void)
close(): void
}