@serenityjs/rust-socket
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

@serenityjs/rust-socket

Rust socket is a UdpSocket wrapper written in Rust to provide a stable streaming of Datagram in NodeJS.

import { Socket } from "@serenityjs/rust-socket"
import { BinaryStream } from "@serenityjs/binarystream"

// Create a new Socket instance.
const socket = new Socket("0.0.0.0", 19132, 100) // Address, Port, TPS

// Start and listen for data.
socket.start((error, datagram) => {
  // Check if any error we received.
  if (error) throw new Error(error);

  // Seperate the values.
  const { identifier, stream } = datagram;

  // Create a new BinaryStream instance.
  const reply = new BinaryStream(stream.getBuffer());

  // Write additional data.
  reply.writeString16("Hello World!")

  // Reply to the incoming datagram!
  datagram.reply(reply);
});

Readme

Keywords

none

Package Sidebar

Install

npm i @serenityjs/rust-socket

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

46.7 kB

Total Files

13

Last publish

Collaborators

  • felipegamer-dev
  • creeperg16
  • nobush
  • pmk744