1.0.7 • Published 3 months ago
@serenityjs/raknet-socket v1.0.7
Raknet Socket
About
Raknet socket is a bare-bones UDP socket that is written in Rust and uses NAPI-RS to export Node native modules for our Typescript and Javascript use!.
Usage
Raknet socket has a super simple and straight forward api for quick and easy setup.
import { Socket } from '@serenityjs/raknet-socket';
// Creates a new udp socket
const socket = new Socket('0.0.0.0', 19132);
// Starts listening for packets
socket.listen(
(error, packet) => {
// Incoming packet
const buffer = Buffer.from('hello world!');
socket.send(buffer, packet.address, packet.port, packet.version);
},
(error, packet) => {
// Outgoing packet
console.log('sent packet with size', packet.buffer.length);
},
);
// Closes the socket
socket.close();